Skip to content

Commit 9199eb6

Browse files
MatteoFaridegenaro
andauthored
feat: add trestle beta command (#2267)
* feat: add trestle beta command Signed-off-by: Matteo Fari <matteofari06@gmail.com> Signed-off-by: degenaro <lou.degenaro@gmail.com> * fix: --beta to give warning & not part of version Signed-off-by: degenaro <lou.degenaro@gmail.com> --------- Signed-off-by: Matteo Fari <matteofari06@gmail.com> Signed-off-by: degenaro <lou.degenaro@gmail.com> Co-authored-by: degenaro <lou.degenaro@gmail.com>
1 parent d16ac11 commit 9199eb6

9 files changed

Lines changed: 1045 additions & 1 deletion

File tree

docs/contributing/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ nav:
44
- OSCAL object model: oscal_object_model.md
55
- Website development: website.md
66
- Developing trestle plugins: plugins.md
7+
- Developing beta features: beta_features.md
78
- Contributors: https://github.com/oscal-compass/compliance-trestle/graphs/contributors
89
- Maintainers: maintainers.md
910
- Developer Certificate of Originality: DCO.md

docs/contributing/beta_features.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Developing beta features
3+
description: Guidance for adding experimental beta features to trestle
4+
---
5+
6+
# Developing beta features
7+
8+
Use beta features for commands or behavior that should be available for early testing without becoming part of the
9+
stable trestle interface yet. Beta features must be explicit opt-ins and should have tests and documentation before they
10+
are registered.
11+
12+
## Register a feature
13+
14+
Register the feature in `trestle/core/beta_features.py`.
15+
16+
```python
17+
BETA_FEATURES = {
18+
'example-feature': BetaFeature(
19+
name='example-feature',
20+
description='Short user-facing description',
21+
commands=['trestle example'],
22+
since_version='4.0.0',
23+
stability='beta',
24+
documentation_url='https://oscal-compass.github.io/compliance-trestle/beta/example-feature',
25+
enabled_by_default=False,
26+
deprecation_version=None,
27+
),
28+
}
29+
```
30+
31+
Feature names should be stable, lower-case, and hyphenated.
32+
33+
## Guard beta behavior
34+
35+
Decorate the command run method with `@beta_feature('<feature-name>')`.
36+
37+
```python
38+
from trestle.core.beta_features import beta_feature
39+
40+
41+
class ExampleCmd(CommandBase):
42+
"""Example beta command."""
43+
44+
name = 'example'
45+
46+
@beta_feature('example-feature')
47+
def _run(self, args: argparse.Namespace) -> int:
48+
"""Run the beta command."""
49+
return CmdReturnCodes.SUCCESS.value
50+
```
51+
52+
When the feature is disabled, the decorator returns a command error and tells the user how to enable the feature.
53+
The decorator also allows `--beta` to run the beta command one time without writing config. Commands without the
54+
decorator will warn that `--beta` is only effective for beta level commands, but will otherwise proceed normally.
55+
56+
## Configuration
57+
58+
`trestle beta enable <feature>` writes enabled features to `.trestle/config.ini` when the current directory is inside a
59+
trestle workspace. Outside a workspace, trestle uses the user-level beta config file.
60+
61+
For CI and other ephemeral environments, `TRESTLE_BETA_FEATURES` can enable features without writing config:
62+
63+
```bash
64+
TRESTLE_BETA_FEATURES=example-feature trestle example
65+
```
66+
67+
Features enabled through `TRESTLE_BETA_FEATURES` cannot be disabled with `trestle beta disable`; remove the feature from
68+
the environment variable instead.
69+
70+
## Documentation checklist
71+
72+
Each beta feature should document:
73+
74+
- What the feature does.
75+
- Which commands or options it enables.
76+
- The expected stability level.
77+
- Known limitations.
78+
- How to enable, use, and disable it.

docs/tutorials/cli.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ description: An introductory tutorial into trestle's CLI and OSCAL use cases
55

66
# trestle CLI Overview and OSCAL usecases
77

8-
The trestle CLI has four primary use cases:
8+
The trestle CLI has five primary use cases:
99

1010
- Serve as tooling to generate and manipulate OSCAL files directly by an end user. The objective is to reduce the complexity of creating and editing workflows. Example commands are: `trestle import`, `trestle create`, `trestle split`, `trestle merge`.
1111
- Act as an automation tool that, by design, can be an integral part of a CI/CD pipeline e.g. `trestle validate`, `trestle tasks`.
1212
- Allow governance of markdown documents so they conform to specific style or structure requirements.
1313
- Canonicalize JSON documents with `trestle canonicalize`. See [Canonicalizing JSON documents](canonicalization.md).
14+
- Manage experimental commands with `trestle beta`.
1415

1516
To support each of these use cases trestle creates an opinionated directory structure to manage governed documents.
1617

@@ -150,6 +151,7 @@ This command will return the current version of Trestle and OSCAL it is using.
150151
Running `trestle version` will return:
151152

152153
> Trestle version v3.x.x based on OSCAL version 1.1.2
154+
> Beta features enabled: none
153155
154156
It can also be used to retrieve the metadata version of the OSCAL object:
155157

@@ -179,6 +181,34 @@ Running `trestle version -n nist -t catalog` will return:
179181

180182
> Version of OSCAL object of nist catalog is: 1.1.2
181183
184+
## `trestle beta`
185+
186+
This command manages experimental features that are available for early testing. Beta features are opt-in and may change
187+
before they become stable.
188+
189+
Use `trestle beta query` to list registered beta features and their current status. Use
190+
`trestle beta query --verbose` for descriptions, commands, and documentation links.
191+
192+
```bash
193+
trestle beta query
194+
trestle beta query --verbose
195+
```
196+
197+
Use `trestle beta enable <feature>` and `trestle beta disable <feature>` to manage a feature.
198+
199+
```bash
200+
trestle beta enable example-feature
201+
trestle beta disable example-feature
202+
```
203+
204+
Use `--beta` on a beta command to run it one time without writing beta state to config. Commands that are not beta
205+
features will warn that `--beta` is only effective for beta level commands, but will otherwise proceed normally.
206+
207+
When the current directory is inside a trestle workspace, beta feature state is stored in `.trestle/config.ini`.
208+
Outside a workspace, trestle uses the user-level beta config file:
209+
`$XDG_CONFIG_HOME/trestle/beta.ini`, or `~/.config/trestle/beta.ini` when `XDG_CONFIG_HOME` is not set. On Windows,
210+
the file is `%APPDATA%\trestle\beta.ini`.
211+
182212
## `trestle init`
183213

184214
This command will create (initialize) a trestle workspace in the current directory with the necessary directory structure and trestle artefacts.

0 commit comments

Comments
 (0)