Skip to content

Commit 53aadd8

Browse files
authored
Edit pass on System.CommandLine (#47693)
1 parent f35d1ee commit 53aadd8

13 files changed

+123
-129
lines changed

docs/standard/commandline/design-guidance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ ms.topic: conceptual
1111

1212
# Design guidance
1313

14-
The following sections present guidance that we recommend you follow when designing a CLI. Think of what your app expects on the command line as similar to what a REST API server expects in the URL. Consistent rules for REST APIs are what make them readily usable to client app developers. In the same way, users of your command-line apps will have a better experience if the CLI design follows common patterns.
14+
The following sections present guidance for designing a CLI. Think of what your app expects on the command line as similar to what a REST API server expects in the URL. Consistent rules for REST APIs are what make them readily usable to client app developers. In the same way, users of your command-line apps will have a better experience if the CLI design follows common patterns.
1515

16-
Once you create a CLI, it is hard to change, especially if your users have used your CLI in scripts they expect to keep running. The guidelines here were developed after the .NET CLI, and it doesn't always follow these guidelines. We are updating the .NET CLI where we can do so without introducing breaking changes. An example of this work is the new design for `dotnet new` in .NET 7.
16+
Once you create a CLI, it is hard to change it, especially if your users have used your CLI in scripts they expect to keep running.
1717

1818
## Symbols
1919

@@ -39,7 +39,7 @@ In particular, avoid using any of the following aliases differently than their c
3939

4040
* `-i` for `--interactive`.
4141

42-
This option signals to the user that they may be prompted for inputs to questions that the command needs answered. For example, prompting for a username. Your CLI may be used in scripts, so use caution in prompting users who have not specified this switch.
42+
This option signals to the user that they might be prompted for inputs to questions that the command needs answered. For example, prompting for a username. Your CLI might be used in scripts, so use caution in prompting users who haven't specified this switch.
4343

4444
* `-o` for `--output`.
4545

docs/standard/commandline/get-started-tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ helpviewer_keywords:
1111
---
1212
# Tutorial: Get started with System.CommandLine
1313

14-
[!INCLUDE [scl-preview](../../../includes/scl-preview.md)]
14+
[!INCLUDE [scl-preview](./includes/preview.md)]
1515

1616
This tutorial shows how to create a .NET command-line app that uses the [`System.CommandLine` library](index.md). You'll begin by creating a simple root command that has one option. Then you'll build on that base, creating a more complex app that contains multiple subcommands and different options for each command.
1717

@@ -166,7 +166,7 @@ Options:
166166
--file The file to read and display on the conso
167167
```
168168

169-
`System.CommandLine.RootCommand` by default provides [Help option](how-to-customize-help.md#customize-help-output), [Version option](syntax.md#version-option) and [Suggest directive](syntax.md#suggest-directive). `ParseResult.Invoke` method is responsible for invoking the action of parsed symbol. It could be the action explicitly defined for our command, or the help action defined by `System.CommandLine` for `System.CommandLine.Help.HelpOption`. Moreover, when it detects any parse errors, it prints them to the standard error, prints help to standard output and returns `1` exit code:
169+
<xref:System.CommandLine.RootCommand> by default provides [Help option](how-to-customize-help.md#customize-help-output), [Version option](syntax.md#version-option), and [Suggest directive](syntax.md#suggest-directive). The <xref:System.CommandLine.ParseResult.Invoke?displayProperty=nameWithType> method is responsible for invoking the action of parsed symbol. It could be the action explicitly defined for the command, or the help action defined by `System.CommandLine` for `System.CommandLine.Help.HelpOption`. Moreover, when it detects any parse errors, it prints them to the standard error, prints help to standard output, and returns `1` as the exit code:
170170

171171
```console
172172
scl --invalid bla

docs/standard/commandline/how-to-configure-the-parser.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ ms.topic: how-to
1212

1313
# How to configure the parser in System.CommandLine
1414

15-
[!INCLUDE [scl-preview](../../../includes/scl-preview.md)]
15+
[!INCLUDE [scl-preview](./includes/preview.md)]
1616

17-
`System.CommandLine.CommandLineConfiguration` is a class that provides properties to configure the parser. It is an optional argument for every `Parse` method, such as `System.CommandLine.Command.Parse` or `System.CommandLine.Parsing.CommandLineParser.Parse`. When it is not provided, the default configuration is used.
17+
<xref:System.CommandLine.CommandLineConfiguration> is a class that provides properties to configure the parser. It is an optional argument for every `Parse` method, such as <xref:System.CommandLine.Command.Parse*?displayProperty=nameWithType> and <xref:System.CommandLine.Parsing.CommandLineParser.Parse*?displayProperty=nameWithType>. When it isn't provided, the default configuration is used.
1818

19-
Every `System.CommandLine.ParseResult` instance has a `System.CommandLine.ParseResult.Configuration` property that returns the configuration used for parsing.
19+
<xref:System.CommandLine.ParseResult> has a <xref:System.CommandLine.ParseResult.Configuration> property that returns the configuration used for parsing.
2020

2121
## Standard output and error
2222

23-
`System.CommandLine.CommandLineConfiguration` makes testing, as well as many extensibility scenarios, easier than using `System.Console`. It exposes two `TextWriter` properties: `Output` and `Error`. These can be set to any `TextWriter` instance, such as a `StringWriter`, which can be used to capture output for testing.
23+
`CommandLineConfiguration` makes testing, as well as many extensibility scenarios, easier than using `System.Console`. It exposes two `TextWriter` properties: `Output` and `Error`. These can be set to any `TextWriter` instance, such as a `StringWriter`, which can be used to capture output for testing.
2424

25-
Let's define a simple command that writes to standard output:
25+
Define a simple command that writes to standard output:
2626

2727
:::code language="csharp" source="snippets/configuration/csharp/Program.cs" id="rootcommand":::
2828

29-
Now, let's use `CommandLineConfiguration` to capture the output:
29+
Now, use `CommandLineConfiguration` to capture the output:
3030

3131
:::code language="csharp" source="snippets/configuration/csharp/Program.cs" id="captureoutput":::
3232

docs/standard/commandline/how-to-customize-help.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.topic: how-to
1212

1313
# Customize help output
1414

15-
Command-line apps typically provide an option to display a brief description of the available commands, options, and arguments. `System.CommandLine` provides `System.CommandLine.Help.HelpOption` that is by default included in the [RootCommand](syntax.md#root-command) options. System.CommandLine.Help.HelpOption generates help output for defined symbols by using the information exposed by `System.CommandLine.Symbol.Name`, `System.CommandLine.Symbol.HelpName`, `System.CommandLine.Symbol.Description`, and other properties like default value or completion sources.
15+
Command-line apps typically provide an option to display a brief description of the available commands, options, and arguments. `System.CommandLine` provides <xref:System.CommandLine.Help.HelpOption>, which is included in the [RootCommand](syntax.md#root-command) options by default. `HelpOption` generates help output for defined symbols by using the information exposed by <xref:System.CommandLine.Symbol.Name>, <xref:System.CommandLine.Option.HelpName>, <xref:System.CommandLine.Symbol.Description>, and other properties like default value or completion sources.
1616

1717
:::code language="csharp" source="snippets/customize-help/csharp/Program.cs" id="original" :::
1818

@@ -45,11 +45,11 @@ dotnet -?
4545
dotnet /?
4646
```
4747

48-
Help output doesn't necessarily show all available commands, arguments, and options. Some of them might be *hidden* via the `System.CommandLine.Symbol.Hidden` property, which means they don't show up in help output (and completions) but can be specified on the command line.
48+
Help output doesn't necessarily show all available commands, arguments, and options. Some of them might be *hidden* via the <xref:System.CommandLine.Symbol.Hidden> property, which means they don't show up in help output (and completions) but can be specified on the command line.
4949

5050
## Help customization
5151

52-
You can customize help output for commands by defining specific help text for each symbol, providing further clarity to users regarding their usage.
52+
You can customize help output for commands by defining specific help text for each symbol, providing further clarity to users regarding their usage.
5353

5454
To customize the name of an option's argument, use the option's `System.CommandLine.Option.HelpName` property.
5555

docs/standard/commandline/how-to-customize-parsing-and-validation.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.topic: how-to
1212

1313
# How to customize parsing and validation in System.CommandLine
1414

15-
[!INCLUDE [scl-preview](../../../includes/scl-preview.md)]
15+
[!INCLUDE [scl-preview](./includes/preview.md)]
1616

1717
By default, System.CommandLine provides a set of built-in parsers that can parse many common types:
1818

@@ -36,21 +36,21 @@ Other types are not supported, but you can create custom parsers for them. You c
3636

3737
Every option, argument, and command can have one or more validators. Validators are used to ensure that the parsed value meets certain criteria. For example, you can validate that a number is positive, or that a string is not empty. You can also create complex validators that check against multiple conditions.
3838

39-
Every symbol type in System.CommandLine has a `Validators` property that contains a list of validators. The validators are executed after the input is parsed, and they can report an error if the validation fails.
39+
Every symbol type in System.CommandLine has a <xref:System.CommandLine.Option.Validators> property that contains a list of validators. The validators are executed after the input is parsed, and they can report an error if the validation fails.
4040

4141
To provide custom validation code, call `System.CommandLine.Option.Validators.Add` on your option or argument (or command), as shown in the following example:
4242

4343
:::code language="csharp" source="snippets/model-binding/csharp/AddValidator.cs" id="delayOption" :::
4444

4545
System.CommandLine provides a set of built-in validators that can be used to validate common types:
4646

47-
- `AcceptExistingOnly` - configures given option or argument to accept only values corresponding to an existing file or directory.
48-
- `AcceptLegalFileNamesOnly` - configures given option or argument to accept only values representing legal file names.
49-
- `AcceptOnlyFromAmong` - configures given option or argument to accept only values from a specified set of values.
47+
* `AcceptExistingOnly` - configures given option or argument to accept only values corresponding to an existing file or directory.
48+
* `AcceptLegalFileNamesOnly` - configures given option or argument to accept only values representing legal file names.
49+
* `AcceptOnlyFromAmong` - configures given option or argument to accept only values from a specified set of values.
5050

5151
## Custom parsers
5252

53-
Custom parsers are required to parse types with no default parser, such as complex types. They can also be used to parse supported types in a different way than the built-in parsers.
53+
To parse types with no default parser, such as complex types, you need a custom parser. Custom parsers can also be used to parse supported types in a different way than the built-in parsers.
5454

5555
Suppose you have a `Person` type:
5656

@@ -75,5 +75,5 @@ Here are some examples of what you can do with `CustomParser` that you can't do
7575

7676
## See also
7777

78-
- [How to parse and invoke the result](how-to-parse-and-invoke.md)
79-
- [System.CommandLine overview](index.md)
78+
* [How to parse and invoke the result](how-to-parse-and-invoke.md)
79+
* [System.CommandLine overview](index.md)

docs/standard/commandline/how-to-enable-tab-completion.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ ms.topic: how-to
1212

1313
# Tab completion for System.CommandLine
1414

15-
[!INCLUDE [scl-preview](../../../includes/scl-preview.md)]
15+
[!INCLUDE [scl-preview](./includes/preview.md)]
1616

17-
Apps that use `System.CommandLine` have built-in support for tab completion in certain shells. To enable it, the end user must take a few steps once per shell. Once this is done, tab completion is automatic for static values in your app, such as enum values or values defined by calling `System.CommandLine.Option<T>.AcceptOnlyFromAmong`. You can also customize tab completion by providing values dynamically at runtime.
17+
Apps that use `System.CommandLine` have built-in support for tab completion in certain shells. To enable it, the end user must take a few steps once per shell. Once this is done, tab completion is automatic for static values in your app, such as enum values or values defined by calling <xref:System.CommandLine.Option`1.AcceptOnlyFromAmong(System.String[])>. You can also customize tab completion by providing values dynamically at runtime.
1818

1919
## Enable tab completion
2020

@@ -59,7 +59,7 @@ The values shown when the Tab key is pressed are provided as `CompletionItem` in
5959
The following `CompletionItem` properties are set:
6060

6161
* `Label` is the completion value to be shown.
62-
* `SortText` ensures that the values in the list are presented in the correct order. It is set by converting `i` to a two-digit string, so that sorting is based on 01, 02, 03, and so on, through 14. If you do not set this parameter, sorting is based on the `Label`, which in this example is in short date format and will not sort correctly.
62+
* `SortText` ensures that the values in the list are presented in the correct order. It is set by converting `i` to a two-digit string, so that sorting is based on 01, 02, 03, and so on, through 14. If you don't set this parameter, sorting is based on the `Label`, which in this example is in short date format and will not sort correctly.
6363

6464
There are other `CompletionItem` properties, such as `Documentation` and `Detail`, but they are not yet used in `System.CommandLine`.
6565

0 commit comments

Comments
 (0)