-
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
Open
adamsitnik
wants to merge
14
commits into
dotnet:main
Choose a base branch
from
adamsitnik:beta5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0157219
Updating docs to beta5: symbols, syntax, getting started guide
adamsitnik ea2caee
Updating docs to beta5: termination, middleware, completions, binding
adamsitnik c8cf7d0
Updating docs to beta5: help customization
adamsitnik f19bdea
move "design guidance" to a dedicated doc, introduce new paragraphs: …
adamsitnik e76e12d
join syntax and "define commands", simplify the descriptions and just…
adamsitnik 3153d7a
improve getting started tutorial: start it with bare minimum sample t…
adamsitnik 9a82823
update Help customization based on our recent changes
adamsitnik f8dbb31
the separation of parsing and invocation
adamsitnik c4c828a
simplify parsing and validation doc, add config doc, polish other docs
adamsitnik 0a11108
Fix grammar and markdown issues using Copilot
adamsitnik b883370
beta5 breaking changes: renaming, the separation of names and aliases…
adamsitnik 5e6c15f
beta5 breaking changes: configuration, invocation, benefits
adamsitnik 8bbb74a
final polishing
adamsitnik e9e0172
fix markdown linter errors, add redirects
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: How to configure the parser in System.CommandLine | ||
description: "Learn how to configure the parser in System.CommandLine." | ||
ms.date: 16/06/2025 | ||
no-loc: [System.CommandLine] | ||
helpviewer_keywords: | ||
- "command line interface" | ||
- "command line" | ||
- "System.CommandLine" | ||
ms.topic: how-to | ||
--- | ||
|
||
# How to configure the parser in System.CommandLine | ||
|
||
[!INCLUDE [scl-preview](../../../includes/scl-preview.md)] | ||
|
||
<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> or <xref:System.CommandLine.Parsing.CommandLineParser.Parse>. When it is not provided, the default configuration is used. | ||
|
||
Every <xref:System.CommandLine.ParseResult> instance has a <xref:System.CommandLine.ParseResult.Configuration> property that returns the configuration used for parsing. | ||
|
||
## Standard output and error | ||
|
||
<xref: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. | ||
|
||
Let's define a simple command that writes to standard output: | ||
|
||
:::code language="csharp" source="snippets/configuration/csharp/Program.cs" id="setaction"::: | ||
|
||
Now, let's use `CommandLineConfiguration` 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 <xref:System.CommandLine.CommandLineConfiguration.EnablePosixBundling> property to `false`. | ||
|
||
## ProcessTerminationTimeout | ||
|
||
[Process termination timeout](parse-and-invoke.md#process-termination-timeout) can be configured via the <xref:System.CommandLine.CommandLineConfiguration.ProcessTerminationTimeout> 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 <xref:System.CommandLine.CommandLineConfiguration.ResponseFileTokenReplacer> property to `null`. You can also provide a custom implementation to customize how response files are processed. | ||
|
||
## EnableDefaultExceptionHandler | ||
|
||
By default, all unhandled exceptions thrown during the invocation of a command are caught and reported to the user. This behavior can be disabled by setting the <xref:System.CommandLine.CommandLineConfiguration.EnableDefaultExceptionHandler> 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 | ||
|
||
<xref:System.CommandLine.CommandLineConfiguration> 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. | ||
|
||
## See also | ||
|
||
- [System.CommandLine overview](index.md) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 as2.0.0-beta5
throughout.