Skip to content

Commit c75a9e0

Browse files
meiranzhengphil-scott-78
authored andcommitted
docs(cli): clarify AddBranch shared settings
1 parent 4b5eed1 commit c75a9e0

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

Spectre.Docs.Cli.Examples/DemoApps/CommandHierarchies/Main.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public class RemoteRemoveSettings : RemoteSettings
7272
public string Name { get; init; } = string.Empty;
7373
}
7474

75+
/// <summary>
76+
/// Settings for listing remotes.
77+
/// </summary>
78+
public class RemoteListSettings : RemoteSettings
79+
{
80+
}
81+
7582
internal class RemoteAddCommand : Command<RemoteAddSettings>
7683
{
7784
protected override int Execute(CommandContext context, RemoteAddSettings settings, CancellationToken cancellation)
@@ -94,9 +101,9 @@ protected override int Execute(CommandContext context, RemoteRemoveSettings sett
94101
}
95102
}
96103

97-
internal class RemoteListCommand : Command<RemoteSettings>
104+
internal class RemoteListCommand : Command<RemoteListSettings>
98105
{
99-
protected override int Execute(CommandContext context, RemoteSettings settings, CancellationToken cancellation)
106+
protected override int Execute(CommandContext context, RemoteListSettings settings, CancellationToken cancellation)
100107
{
101108
System.Console.WriteLine("Listing remotes...");
102109
if (settings.Verbose)

Spectre.Docs/Content/cli/how-to/working-with-multiple-command-hierarchies.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A git-style CLI with nested `remote` subcommands—`add`, `remove`, and `list`
1515

1616
## Create a Command Branch
1717

18-
Use `AddBranch<TSettings>("name", ...)` to define a parent command with nested subcommands:
18+
Use `AddBranch` to define a parent command with nested subcommands. Use the generic overload when you want shared settings/options for the branch:
1919

2020
```csharp:xmldocid,bodyonly
2121
M:Spectre.Docs.Cli.Examples.DemoApps.CommandHierarchies.Demo.RunAsync(System.String[])
@@ -30,13 +30,16 @@ Define a base settings class for the branch, then inherit from it in subcommand
3030
```csharp:xmldocid
3131
T:Spectre.Docs.Cli.Examples.DemoApps.CommandHierarchies.RemoteSettings
3232
T:Spectre.Docs.Cli.Examples.DemoApps.CommandHierarchies.RemoteAddSettings
33+
T:Spectre.Docs.Cli.Examples.DemoApps.CommandHierarchies.RemoteListSettings
3334
```
3435

35-
The `--verbose` flag is now available on all remote subcommands: `myapp remote add origin https://... --verbose`.
36+
The `--verbose` flag is now available on all remote subcommands, and can be specified either before or after the subcommand name: `myapp remote --verbose add origin https://...` or `myapp remote add origin https://... --verbose`.
37+
38+
Tip: even if a subcommand doesn't add any extra arguments/options (like `list`), give it a dedicated settings type that inherits from the branch settings (for example, `RemoteListSettings : RemoteSettings`).
3639

3740
## Nest Multiple Levels
3841

39-
For complex CLIs, branches can contain other branches:
42+
For complex CLIs, branches can contain other branches (use the non-generic overload when you just want grouping):
4043

4144
```csharp
4245
config.AddBranch("cloud", cloud =>
@@ -54,4 +57,4 @@ This creates deeply nested commands like `myapp cloud storage upload`.
5457
## See Also
5558

5659
- <xref:cli-app-configuration> - Basic command registration
57-
- <xref:cli-commands-arguments> - Settings class patterns
60+
- <xref:cli-commands-arguments> - Settings class patterns

0 commit comments

Comments
 (0)