You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/aesh/command-definition.md
+141Lines changed: 141 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ The `@CommandDefinition` annotation is used to define a command class.
28
28
|`defaultValueProvider`|`Class<? extends DefaultValueProvider>`|`NullDefaultValueProvider.class`| Dynamic default value resolver |
29
29
|`stopAtFirstPositional`|`boolean`|`false`| Stop option parsing after the first positional argument |
30
30
|`helpUrl`|`String`|`""`| URL to documentation (shown in `--help` output) |
31
+
|`helpGroup`|`String`|`""`| Group heading when listed as a subcommand in parent's help |
32
+
|`helpSectionProvider`|`Class<? extends HelpSectionProvider>`|`NullHelpSectionProvider.class`| Provider for dynamic help sections |
31
33
32
34
## Example
33
35
@@ -182,3 +184,142 @@ Provides access to:
182
184
-`stop()` - Stop the console
183
185
-`getShell()` - Access the shell
184
186
-`getHelpInfo(String)` - Get help text
187
+
188
+
## Help Group for Subcommands
189
+
190
+
The `helpGroup` property on `@CommandDefinition` (and `@GroupCommandDefinition`) controls how a subcommand appears in its parent's help output. Subcommands with the same `helpGroup` value are displayed together under that heading.
1. Subcommands with the same `helpGroup` value are grouped under that heading
252
+
2. Named groups appear first, in the order their first subcommand was defined
253
+
3. Subcommands without a `helpGroup` appear under a default heading
254
+
4. If all subcommands have a `helpGroup`, there is no default group
255
+
256
+
This is separate from the `helpGroup` property on `@Option`, which groups options within a single command's help output. See [Options - Help Grouping](/docs/aesh/options#help-grouping).
257
+
258
+
## Help Section Provider
259
+
260
+
The `helpSectionProvider` property lets you dynamically add sections to a command's help output at render time. This is useful for showing external plugins, aliases, or dynamically discovered commands without statically defining them.
261
+
262
+
### Implementing a Provider
263
+
264
+
Create a class that implements `HelpSectionProvider`:
If a provider section name matches an existing `helpGroup` from statically defined subcommands, the entries are appended to that group rather than creating a duplicate heading.
319
+
320
+
### Key Points
321
+
322
+
1.**Zero startup cost** -- The provider class is stored as a reference and only instantiated when help is rendered
323
+
2.**Works with both `@CommandDefinition` and `@GroupCommandDefinition`**
324
+
3.**HelpEntry** is a simple value class with `name()` and `description()` (description is optional)
325
+
4.**Return an empty map** (not null) if there are no additional sections to show
The `exclusiveWith` property declares that two or more options cannot be used together. If a user provides both, a `MutuallyExclusiveOptionException` is thrown during parsing.
# Invalid -- mutually exclusive options used together
581
+
$ export --json --xml
582
+
Error: Options --json and --xml are mutually exclusive.
583
+
```
584
+
585
+
### How It Works
586
+
587
+
1. Each option lists the names of options it conflicts with (long names, without the `--` prefix)
588
+
2. The relationship should be declared on both sides: if `--json` lists `xml`, then `--xml` should list `json`
589
+
3. Validation runs after parsing, at the same point as required option checks
590
+
4. Non-exclusive options (like `--verbose` above) can be freely combined with any exclusive option
591
+
592
+
### Tab Completion
593
+
594
+
When an exclusive option has been set, conflicting options are automatically filtered from tab completion. For example, after typing `export --json`, pressing Tab will not suggest `--xml` or `--csv`.
595
+
596
+
### With OptionList
597
+
598
+
`exclusiveWith` also works with `@OptionList`:
599
+
600
+
```java
601
+
@OptionList(description="Items to process", exclusiveWith= {"file"})
602
+
privateList<String> items;
603
+
604
+
@Option(description="Read items from file", exclusiveWith= {"items"})
605
+
privateString file;
606
+
```
607
+
608
+
### Programmatic API
609
+
610
+
When building commands programmatically, use `ProcessedOptionBuilder`:
611
+
612
+
```java
613
+
ProcessedOptionBuilder.builder()
614
+
.name("json")
615
+
.type(boolean.class)
616
+
.hasValue(false)
617
+
.exclusiveWith("xml", "csv")
618
+
.build();
619
+
```
620
+
621
+
## Visibility Levels
622
+
623
+
The `visibility` property controls whether an option appears in `--help` output and tab completion. This is useful for organizing help output by importance — showing essential options by default and revealing advanced or deprecated options only on request.
-h, --help Display help (use --help=all for all options)
672
+
```
673
+
674
+
Full help reveals advanced options:
675
+
676
+
```bash
677
+
$ serve --help=all
678
+
Usage: serve [<options>]
679
+
Start server
680
+
681
+
Options:
682
+
-p, --port Server port
683
+
--host Bind address
684
+
--trace Enable request tracing
685
+
--threads Thread pool size
686
+
-h, --help Display help (use --help=all for all options)
687
+
```
688
+
689
+
The `--diagnosticToken` option never appears in help but still works when typed explicitly.
690
+
691
+
### When to Use Each Level
692
+
693
+
-**`BRIEF`** — Options every user needs to know about. This is the default; existing commands are unaffected.
694
+
-**`FULL`** — Advanced tuning, debugging, or rarely-used options. Power users can discover them with `--help=all`.
695
+
-**`HIDDEN`** — Internal, deprecated, or experimental options that should not be discoverable. They still parse and work when used explicitly.
696
+
697
+
### Tab Completion
698
+
699
+
`HIDDEN` options are excluded from tab completion. `BRIEF` and `FULL` options are both offered during completion — visibility only affects help output for `FULL` options.
700
+
701
+
### With Help Grouping
702
+
703
+
Visibility works with `helpGroup`. A group heading is only printed if it contains at least one visible option:
0 commit comments