From 209b280b2a305828728f551a774277d8a0d0c3d3 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 29 Aug 2025 15:03:44 +0200 Subject: [PATCH 1/4] bump System.CommandLine to beta7 to ensure they can be compiled with the latest version that will have no breaking changes with the upcoming RTM release --- .../commandline/snippets/customize-help/csharp/scl.csproj | 2 +- .../commandline/snippets/define-symbols/csharp/scl.csproj | 2 +- .../snippets/get-started-tutorial/csharp/Stage0/scl.csproj | 2 +- .../snippets/get-started-tutorial/csharp/Stage1/scl.csproj | 2 +- .../snippets/get-started-tutorial/csharp/Stage2/scl.csproj | 2 +- .../snippets/get-started-tutorial/csharp/Stage3/scl.csproj | 2 +- .../commandline/snippets/handle-termination/csharp/scl.csproj | 2 +- .../commandline/snippets/model-binding/csharp/scl.csproj | 2 +- .../commandline/snippets/tab-completion/csharp/scl.csproj | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/standard/commandline/snippets/customize-help/csharp/scl.csproj b/docs/standard/commandline/snippets/customize-help/csharp/scl.csproj index 2383cc5cdf20f..ff64d6d874e91 100644 --- a/docs/standard/commandline/snippets/customize-help/csharp/scl.csproj +++ b/docs/standard/commandline/snippets/customize-help/csharp/scl.csproj @@ -11,7 +11,7 @@ - + diff --git a/docs/standard/commandline/snippets/define-symbols/csharp/scl.csproj b/docs/standard/commandline/snippets/define-symbols/csharp/scl.csproj index 3fa68e1bda8bd..88b6015180700 100644 --- a/docs/standard/commandline/snippets/define-symbols/csharp/scl.csproj +++ b/docs/standard/commandline/snippets/define-symbols/csharp/scl.csproj @@ -8,7 +8,7 @@ - + diff --git a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/scl.csproj b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/scl.csproj index 3fa68e1bda8bd..88b6015180700 100644 --- a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/scl.csproj +++ b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/scl.csproj @@ -8,7 +8,7 @@ - + diff --git a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage1/scl.csproj b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage1/scl.csproj index 353904e7371a8..a90fcf7961904 100644 --- a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage1/scl.csproj +++ b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage1/scl.csproj @@ -8,7 +8,7 @@ - + diff --git a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage2/scl.csproj b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage2/scl.csproj index ba34104135bb3..a08635cf763c2 100644 --- a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage2/scl.csproj +++ b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage2/scl.csproj @@ -14,7 +14,7 @@ - + diff --git a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage3/scl.csproj b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage3/scl.csproj index 25c683965dbf7..c8f6b6b303d1b 100644 --- a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage3/scl.csproj +++ b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage3/scl.csproj @@ -8,7 +8,7 @@ - + diff --git a/docs/standard/commandline/snippets/handle-termination/csharp/scl.csproj b/docs/standard/commandline/snippets/handle-termination/csharp/scl.csproj index 3fa68e1bda8bd..88b6015180700 100644 --- a/docs/standard/commandline/snippets/handle-termination/csharp/scl.csproj +++ b/docs/standard/commandline/snippets/handle-termination/csharp/scl.csproj @@ -8,7 +8,7 @@ - + diff --git a/docs/standard/commandline/snippets/model-binding/csharp/scl.csproj b/docs/standard/commandline/snippets/model-binding/csharp/scl.csproj index 999c4cf409320..200c5c83f2204 100644 --- a/docs/standard/commandline/snippets/model-binding/csharp/scl.csproj +++ b/docs/standard/commandline/snippets/model-binding/csharp/scl.csproj @@ -9,7 +9,7 @@ - + diff --git a/docs/standard/commandline/snippets/tab-completion/csharp/scl.csproj b/docs/standard/commandline/snippets/tab-completion/csharp/scl.csproj index 77b39921e4475..9e7c67f1f9ccb 100644 --- a/docs/standard/commandline/snippets/tab-completion/csharp/scl.csproj +++ b/docs/standard/commandline/snippets/tab-completion/csharp/scl.csproj @@ -9,7 +9,7 @@ - + From 6ca1754faf11802a7160b3889ed36f9d997bb7d8 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 29 Aug 2025 15:15:53 +0200 Subject: [PATCH 2/4] check for errors before calling GetValue, as it may throw when there are errors --- .../snippets/get-started-tutorial/csharp/Stage0/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/Program.cs b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/Program.cs index e86720a7c663a..8343604cc46d1 100644 --- a/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/Program.cs +++ b/docs/standard/commandline/snippets/get-started-tutorial/csharp/Stage0/Program.cs @@ -20,7 +20,7 @@ static int Main(string[] args) // ParseResult parseResult = rootCommand.Parse(args); - if (parseResult.GetValue(fileOption) is FileInfo parsedFile) + if (parseResult.Errors.Count == 0 && parseResult.GetValue(fileOption) is FileInfo parsedFile) { ReadFile(parsedFile); return 0; From dadba115ea6380659888efd302805650165e52dc Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 29 Aug 2025 15:30:01 +0200 Subject: [PATCH 3/4] update the docs to beta7 --- .../how-to-configure-the-parser.md | 35 +++++++++++-------- docs/standard/commandline/includes/preview.md | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/standard/commandline/how-to-configure-the-parser.md b/docs/standard/commandline/how-to-configure-the-parser.md index c7d2bd35a0edb..d75755fdce0e5 100644 --- a/docs/standard/commandline/how-to-configure-the-parser.md +++ b/docs/standard/commandline/how-to-configure-the-parser.md @@ -14,11 +14,26 @@ ms.topic: how-to [!INCLUDE [scl-preview](./includes/preview.md)] - is a class that provides properties to configure the parser. It is an optional argument for every `Parse` method, such as and . When it isn't provided, the default configuration is used. +Parsing and invocation are two separate steps, so each of them has their own configuration: - has a property that returns the configuration used for parsing. +- is a class that provides properties to configure the parsing. It is an optional argument for every `Parse` method, such as and . +- is a class that provides properties to configure the invocation. It is an optional argument of the and methods. -## Standard output and error +They are exposed by the and properties. When they aren't provided, the default configurations are used. + +## ParserConfiguration + +### EnablePosixBundling + +[Bundling](syntax.md#option-bundling) of single-character options is enabled by default, but you can disable it by setting the property to `false`. + +### ResponseFileTokenReplacer + +[Response files](syntax.md#response-files) are enabled by default, but you can disable them by setting the property to `null`. You can also provide a custom implementation to customize how response files are processed. + +## InvocationConfiguration + +### Standard output and error makes testing, as well as many extensibility scenarios, easier than using `System.Console`. It exposes two `TextWriter` properties: and . You can set these properties to any `TextWriter` instance, such as a `StringWriter`, which you can use to capture output for testing. @@ -30,23 +45,15 @@ Now, use to capture the output :::code language="csharp" source="snippets/configuration/csharp/Program.cs" id="captureoutput"::: -## EnablePosixBundling - -[Bundling](syntax.md#option-bundling) of single-character options is enabled by default, but you can disable it by setting the property to `false`. - -## ProcessTerminationTimeout +### ProcessTerminationTimeout [Process termination timeout](how-to-parse-and-invoke.md#process-termination-timeout) can be configured via the property. The default value is 2 seconds. -## ResponseFileTokenReplacer - -[Response files](syntax.md#response-files) are enabled by default, but you can disable them by setting the property to `null`. You can also provide a custom implementation to customize how response files are processed. - -## EnableDefaultExceptionHandler +### EnableDefaultExceptionHandler By default, all unhandled exceptions thrown during the invocation of a command are caught and reported to the user. You can disable this behavior by setting the property to `false`. This is useful when you want to handle exceptions in a custom way, such as logging them or providing a different user experience. -## Derived classes +### Derived classes is not sealed, so you can derive from it to add custom properties or methods. This is useful when you want to provide additional configuration options specific to your application. diff --git a/docs/standard/commandline/includes/preview.md b/docs/standard/commandline/includes/preview.md index c659ec643076e..247499ccbc93c 100644 --- a/docs/standard/commandline/includes/preview.md +++ b/docs/standard/commandline/includes/preview.md @@ -3,5 +3,5 @@ ms.date: 07/31/2025 ms.topic: include --- > [!IMPORTANT] -> `System.CommandLine` is currently in preview. This documentation is for version 2.0 beta 5. +> `System.CommandLine` is currently in preview. This documentation is for version 2.0 beta 7. > Some information relates to prerelease product that might be substantially modified before it's released. Microsoft makes no warranties, express or implied, with respect to the information provided here. From e101c4d200e5055661ddc9c2302131d9ea2cd542 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 29 Aug 2025 15:35:44 +0200 Subject: [PATCH 4/4] no trailing spaces ;) --- docs/standard/commandline/how-to-configure-the-parser.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/commandline/how-to-configure-the-parser.md b/docs/standard/commandline/how-to-configure-the-parser.md index d75755fdce0e5..0b01feda21dea 100644 --- a/docs/standard/commandline/how-to-configure-the-parser.md +++ b/docs/standard/commandline/how-to-configure-the-parser.md @@ -17,7 +17,7 @@ ms.topic: how-to Parsing and invocation are two separate steps, so each of them has their own configuration: - is a class that provides properties to configure the parsing. It is an optional argument for every `Parse` method, such as and . -- is a class that provides properties to configure the invocation. It is an optional argument of the and methods. +- is a class that provides properties to configure the invocation. It is an optional argument of the and methods. They are exposed by the and properties. When they aren't provided, the default configurations are used.