diff --git a/docs/standard/commandline/how-to-configure-the-parser.md b/docs/standard/commandline/how-to-configure-the-parser.md index c7d2bd35a0edb..0b01feda21dea 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. 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/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; 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 @@ - +