-
Notifications
You must be signed in to change notification settings - Fork 6k
System.CommandLine docs update #46594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…symbols and naming
… briefly mention features that are not expected to be used frequently like Recursive or Hidden symbols rename "Help Customization" to just "Help" and move "HelpOption" description there
…hat does not use invocation at all, then use help to explain what invocation is and what it provides
…, exposing mutable collections, default value changes
ms.topic: conceptual | ||
--- | ||
|
||
# Design guidance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just moved this text, the source: https://github.com/dotnet/docs/blob/main/docs/standard/commandline/syntax.md#design-guidance
|
||
[!INCLUDE [scl-preview](../../../includes/scl-preview.md)] | ||
|
||
Our main focus for beta5 was to improve the APIs and take a step toward releasing a stable version of System.CommandLine. We have simplified the APIs and made them more consistent and coherent with the [Framework design guidelines](../design-guidelines/index.md). This article describes the breaking changes that were made in beta5 and the reasoning behind them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our main focus for beta5 was to improve the APIs and take a step toward releasing a stable version of System.CommandLine. We have simplified the APIs and made them more consistent and coherent with the [Framework design guidelines](../design-guidelines/index.md). This article describes the breaking changes that were made in beta5 and the reasoning behind them. | |
Our main focus for beta5 was to improve the APIs and take a step toward releasing a stable version of System.CommandLine. We have simplified the APIs and made them more coherent and consistent with the [Framework design guidelines](../design-guidelines/index.md). This article describes the breaking changes that were made in beta5 and the reasoning behind them. |
|
||
### Creating options with aliases | ||
|
||
In the past, `Option<T>` was exposing plenty of constructors, some of which were accepting the name or not. Since the name is now mandatory and we expect aliases to be frequetly provided for `Option<T>`, we provide only a single constrtor. It accepts the name and a `params` array of aliases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past, `Option<T>` was exposing plenty of constructors, some of which were accepting the name or not. Since the name is now mandatory and we expect aliases to be frequetly provided for `Option<T>`, we provide only a single constrtor. It accepts the name and a `params` array of aliases. | |
In the past, `Option<T>` exposed many constructors, some of which accepted the name. Since the name is now mandatory and we expect aliases to be frequently provided for `Option<T>`, we provide only a single constructor. It accepts the name and a `params` array of aliases. |
|
||
Before beta5, `Option<T>` had a constructor that took a name and a description. Because of that, the second argument might now be treated as an alias rather than a description. It's the only known breaking change in the API that is not going to cause a compiler error. | ||
|
||
Old code that used the constructor with a description should be updated to use the new constructor that takes a name and aliases, and then set the `Description` property separately. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old code that used the constructor with a description should be updated to use the new constructor that takes a name and aliases, and then set the `Description` property separately. For example: | |
Old code that used the constructor with a description should be updated to use the new constructor which takes a name and aliases, and then set the `Description` property separately. For example: |
|
||
## Default values | ||
|
||
In beta4, users could set default values for options and arguments by using the `SetDefaultValue` methods. Those methods were accepting an `object` value, which was not type-safe and could lead to runtime errors if the value was not compatible with the option or argument type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In beta4, users could set default values for options and arguments by using the `SetDefaultValue` methods. Those methods were accepting an `object` value, which was not type-safe and could lead to runtime errors if the value was not compatible with the option or argument type: | |
In beta4, users could set default values for options and arguments by using the `SetDefaultValue` methods. Those methods accepted an `object` value, which was not type-safe and could lead to runtime errors if the value was not compatible with the option or argument type: |
|
||
Moreover, some of the `Option` and `Argument` constructors accepted a parse delegate and a boolean indicating whether the delegate was a custom parser or a default value provider. This was confusing. | ||
|
||
`Option<T>` and `Argument<T>` classes now have a `DefaultValueFactory` property that can be used to set the default value for the symbol. This property is invoked when the symbol is not provided in the command line input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`Option<T>` and `Argument<T>` classes now have a `DefaultValueFactory` property that can be used to set the default value for the symbol. This property is invoked when the symbol is not provided in the command line input. | |
`Option<T>` and `Argument<T>` classes now have a `DefaultValueFactory` property that can be used to set a delegate that can be called to get the default value for the option or argument. This delegate is invoked when the option or argument is not found in the parsed command line input. |
}; | ||
``` | ||
|
||
## Default values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Default values | |
## Default values and custom parsing |
}; | ||
``` | ||
|
||
Moreover, `CustomParser` accepts `Func<ParseResult, T>` delegate, rather than dedicated `ParseArgument` delegate. This and few other custom delegates were removed to simplify the API and reduce the number of types exposed by the API and compiled at startup time by the JIT compiler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, `CustomParser` accepts `Func<ParseResult, T>` delegate, rather than dedicated `ParseArgument` delegate. This and few other custom delegates were removed to simplify the API and reduce the number of types exposed by the API and compiled at startup time by the JIT compiler. | |
Moreover, `CustomParser` accepts a delegate of type `Func<ParseResult, T>`, rather than the previous `ParseArgument` delegate. This and a few other custom delegates were removed to simplify the API and reduce the number of types exposed by the API, which reduces startup time spent during JIT compilation. |
|
||
For more examples of how to use `DefaultValueFactory` and `CustomParser`, see the [How to customize parsing and validation in System.CommandLine](parsing-and-validation.md) document. | ||
|
||
## The separation of parsing and invoking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## The separation of parsing and invoking | |
## The separation of parsing and invocation |
|
||
## The separation of parsing and invoking | ||
|
||
In beta4, it was possible to separate the parsing and invoking of commands, but it was quite unclear how to do it. The `Command` was not exposing a `Parse` method, but `CommandExtensions` was providing `Parse`, `Invoke`, and `InvokeAsync` extension methods for `Command`. This was confusing, as it was not clear which method to use and when. Following changes were made to simplify the API: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In beta4, it was possible to separate the parsing and invoking of commands, but it was quite unclear how to do it. The `Command` was not exposing a `Parse` method, but `CommandExtensions` was providing `Parse`, `Invoke`, and `InvokeAsync` extension methods for `Command`. This was confusing, as it was not clear which method to use and when. Following changes were made to simplify the API: | |
In beta4, it was possible to separate the parsing and invoking of commands, but it was quite unclear how to do it. `Command` did not expose a `Parse` method, but `CommandExtensions` provided `Parse`, `Invoke`, and `InvokeAsync` extension methods for `Command`. This was confusing, as it was not clear which method to use and when. The following changes were made to simplify the API: |
|
||
## Renaming | ||
|
||
In beta4, not all types and properties followed the [naming guidelines](../design-guidelines/naming-guidelines.md). Some were not consistent with the naming conventions, such as using the `Is` prefix for boolean properties. In beta5, we have renamed some types and properties. The following table shows the old and new names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In beta4, not all types and properties followed the [naming guidelines](../design-guidelines/naming-guidelines.md). Some were not consistent with the naming conventions, such as using the `Is` prefix for boolean properties. In beta5, we have renamed some types and properties. The following table shows the old and new names: | |
In beta4, not all types and members followed the [naming guidelines](../design-guidelines/naming-guidelines.md). Some were not consistent with the naming conventions, such as using the `Is` prefix for boolean properties. In beta5, we have renamed some types and members. The following table shows the old and new names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps pedantic of me, but I recommend renaming this to 2.0.0-beta5
and generally referring to the release as 2.0.0-beta5
throughout.
title: System.CommandLine beta5 breaking changes | ||
description: "Learn what breaking changes were introduced in beta5 and why." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: System.CommandLine beta5 breaking changes | |
description: "Learn what breaking changes were introduced in beta5 and why." | |
title: System.CommandLine 2.0.0-beta5 breaking changes | |
description: "Learn what breaking changes were introduced in 2.0.0-beta5 and why." |
ms.topic: how-to | ||
--- | ||
|
||
# Breaking changes in beta5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Breaking changes in beta5 | |
# Breaking changes in 2.0.0-beta5 |
|
||
## Renaming | ||
|
||
In beta4, not all types and properties followed the [naming guidelines](../design-guidelines/naming-guidelines.md). Some were not consistent with the naming conventions, such as using the `Is` prefix for boolean properties. In beta5, we have renamed some types and properties. The following table shows the old and new names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In beta4, not all types and properties followed the [naming guidelines](../design-guidelines/naming-guidelines.md). Some were not consistent with the naming conventions, such as using the `Is` prefix for boolean properties. In beta5, we have renamed some types and properties. The following table shows the old and new names: | |
In 2.0.0-beta4, not all types and properties followed the [naming guidelines](../design-guidelines/naming-guidelines.md). Some were not consistent with the naming conventions, such as using the `Is` prefix for boolean properties. In 2.0.0-beta5, we have renamed some types and properties. The following table shows the old and new names: |
|
||
In beta4, it was possible to separate the parsing and invoking of commands, but it was quite unclear how to do it. The `Command` was not exposing a `Parse` method, but `CommandExtensions` was providing `Parse`, `Invoke`, and `InvokeAsync` extension methods for `Command`. This was confusing, as it was not clear which method to use and when. Following changes were made to simplify the API: | ||
|
||
- `Command` now exposes a `Parse` method that returns a `ParseResult` object. This method is used to parse the command line input and return the result of the parsing. Moreover, it makes it clear that the command is not invoked, but only parsed and only in synchronous manner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `Command` now exposes a `Parse` method that returns a `ParseResult` object. This method is used to parse the command line input and return the result of the parsing. Moreover, it makes it clear that the command is not invoked, but only parsed and only in synchronous manner. | |
- `Command` now exposes a `Parse` method that returns a `ParseResult` object. This method is used to parse the command line input and return the result of the parse operation. Moreover, it makes it clear that the command is not invoked, but only parsed and only in synchronous manner. |
High level overview:
Internal previews
Toggle expand/collapse