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: docs/standard/commandline/design-guidance.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,9 @@ ms.topic: conceptual
11
11
12
12
# Design guidance
13
13
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.
15
15
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.
17
17
18
18
## Symbols
19
19
@@ -39,7 +39,7 @@ In particular, avoid using any of the following aliases differently than their c
39
39
40
40
*`-i` for `--interactive`.
41
41
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.
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.
17
17
@@ -166,7 +166,7 @@ Options:
166
166
--file The file to read and display on the conso
167
167
```
168
168
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:
`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.
18
18
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.
20
20
21
21
## Standard output and error
22
22
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.
24
24
25
-
Let's define a simple command that writes to standard output:
25
+
Define a simple command that writes to standard output:
Copy file name to clipboardExpand all lines: docs/standard/commandline/how-to-customize-help.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ ms.topic: how-to
12
12
13
13
# Customize help output
14
14
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.
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.
49
49
50
50
## Help customization
51
51
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.
53
53
54
54
To customize the name of an option's argument, use the option's `System.CommandLine.Option.HelpName` property.
By default, System.CommandLine provides a set of built-in parsers that can parse many common types:
18
18
@@ -36,21 +36,21 @@ Other types are not supported, but you can create custom parsers for them. You c
36
36
37
37
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.
38
38
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.
40
40
41
41
To provide custom validation code, call `System.CommandLine.Option.Validators.Add` on your option or argument (or command), as shown in the following example:
System.CommandLine provides a set of built-in validators that can be used to validate common types:
46
46
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.
50
50
51
51
## Custom parsers
52
52
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.
54
54
55
55
Suppose you have a `Person` type:
56
56
@@ -75,5 +75,5 @@ Here are some examples of what you can do with `CustomParser` that you can't do
75
75
76
76
## See also
77
77
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)
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.
18
18
19
19
## Enable tab completion
20
20
@@ -59,7 +59,7 @@ The values shown when the Tab key is pressed are provided as `CompletionItem` in
59
59
The following `CompletionItem` properties are set:
60
60
61
61
* `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.
63
63
64
64
There are other `CompletionItem` properties, such as `Documentation` and `Detail`, but they are not yet used in `System.CommandLine`.
0 commit comments