Skip to content

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
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

System.CommandLine docs update #46594

wants to merge 19 commits into from

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Jun 6, 2025

High level overview:

  1. I've merged the doc that explains the syntax (https://learn.microsoft.com/en-us/dotnet/standard/commandline/syntax) without showing the code and the doc that shows the related code (https://learn.microsoft.com/en-us/dotnet/standard/commandline/define-commands) into one.
  2. I've moved the "Command-line design guidance" from syntax doc to a dedicated doc (it's big and important, but the very new users don't need to ready it when learning about syntax for the first time).
  3. I've introduced a dedicated doc about how to parse and invoke to show it's two separate things.
  4. I've introduced dedicated doc about other features such as parsing and validation etc
  5. I've simplified the tutorial to start with a code that does not use invoking at all, just to show all its benefits and gradually use more features.

Internal previews

Toggle expand/collapse
📄 File 🔗 Preview link
docs/fundamentals/toc.yml docs/fundamentals/toc
docs/standard/commandline/2.0.0-beta5.md Breaking changes in System.CommandLine 2.0.0-beta5
docs/standard/commandline/command-line-configuration.md How to configure the parser in System.CommandLine
docs/standard/commandline/design-guidance.md Design guidance
docs/standard/commandline/get-started-tutorial.md Tutorial: Get started with System.CommandLine
docs/standard/commandline/help.md docs/standard/commandline/help
docs/standard/commandline/index.md System.CommandLine overview
docs/standard/commandline/parse-and-invoke.md "How to parse and invoke the result"
docs/standard/commandline/parsing-and-validation.md How to customize parsing and validation in System.CommandLine
docs/standard/commandline/syntax.md Syntax overview: Commands, options, and arguments
docs/standard/commandline/tab-completion.md docs/standard/commandline/tab-completion

@adamsitnik adamsitnik requested review from tdykstra and a team as code owners June 6, 2025 19:01
@dotnetrepoman dotnetrepoman bot added this to the June 2025 milestone Jun 6, 2025
@adamsitnik adamsitnik requested a review from gewarren June 16, 2025 21:05
Copy link
Contributor

@gewarren gewarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding all these docs!


Arguments can have expected types, and `System.CommandLine` displays an error message if an argument can't be parsed into the expected type. For example, the following command errors because "silent" isn't one of the valid values for `--verbosity`:
## Parse Errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Parse Errors
## Parse errors

@@ -139,18 +170,16 @@ dotnet add package System.CommandLine --prerelease --no-restore --source https:/
dotnet add package System.CommandLine --source https://api.nuget.org/v3/index.json --no-restore --prerelease
```

When there are multiple arguments, the order does matter. The following commands are not necessarily equivalent:
When there are multiple arguments, the order does matter. The following commands are not equivalent, they differ in the order of the values, which could lead to different results:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When there are multiple arguments, the order does matter. The following commands are not equivalent, they differ in the order of the values, which could lead to different results:
When there are multiple arguments, the order does matter. The following commands are not equivalent; they differ in the order of the values, which could lead to different results:

@@ -170,7 +199,11 @@ dotnet publish --ou ./publish
dotnet publish --o ./publish
```

`System.CommandLine` doesn't support automatic aliases.
`System.CommandLine` doesn't support automatic aliases, each alias needs to be specified in explicit way. Both commands and options expose `Aliases` property, but `Option` has a constructor that accepts aliases as parameters, so you can define an option with multiple aliases in a single line:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`System.CommandLine` doesn't support automatic aliases, each alias needs to be specified in explicit way. Both commands and options expose `Aliases` property, but `Option` has a constructor that accepts aliases as parameters, so you can define an option with multiple aliases in a single line:
`System.CommandLine` doesn't support automatic aliases. Each alias must be specified explicitly. Both commands and options expose an `Aliases` property. `Option` has a constructor that accepts aliases as parameters, so you can define an option with multiple aliases in a single line:


Both users and developers may find it useful to see how an app will interpret a given input. One of the default features of a `System.CommandLine` app is the `[parse]` directive, which lets you preview the result of parsing command input. For example:
Both users and developers may find it useful to see how an app will interpret a given input. One of the default features of a `System.CommandLine` app is the `[diagram]` directive, which lets you preview the result of parsing command input. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Both users and developers may find it useful to see how an app will interpret a given input. One of the default features of a `System.CommandLine` app is the `[diagram]` directive, which lets you preview the result of parsing command input. For example:
Both users and developers might find it useful to see how an app will interpret a given input. One of the default features of a `System.CommandLine` app is the `[diagram]` directive, which lets you preview the result of parsing command input. For example:

@@ -28,7 +28,7 @@ For other command-line apps built on `System.CommandLine`:

* Install the [`dotnet-suggest`](https://nuget.org/packages/dotnet-suggest) global tool.

* Add the appropriate shim script to your shell profile. You may have to create a shell profile file. The shim script forwards completion requests from your shell to the `dotnet-suggest` tool, which delegates to the appropriate `System.CommandLine`-based app.
* Add the appropriate shim script to your shell profile. You may need to create a shell profile file. The shim script forwards completion requests from your shell to the `dotnet-suggest` tool, which delegates them to the appropriate `System.CommandLine`-based app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add the appropriate shim script to your shell profile. You may need to create a shell profile file. The shim script forwards completion requests from your shell to the `dotnet-suggest` tool, which delegates them to the appropriate `System.CommandLine`-based app.
* Add the appropriate shim script to your shell profile. You might need to create a shell profile file. The shim script forwards completion requests from your shell to the `dotnet-suggest` tool, which delegates them to the appropriate `System.CommandLine`-based app.

jeffhandley and others added 3 commits June 18, 2025 11:46
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: Jon Sequeira <jonsequeira@gmail.com>
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really awesome to see some traction in this area, thanks you! Here are some improvements I found.

---
title: How to configure the parser in System.CommandLine
description: "Learn how to configure the parser in System.CommandLine."
ms.date: 16/06/2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dates are MM/DD/YYYY

@@ -0,0 +1,330 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't name this file the version of the package, a new version means that a redirect has to be created and a file renamed. We also have a standard issue template for a "breaking change" doc, which we can use AI automation to generate details for. This article feels a little more like a "migration from beta 4 to beta 5" and would eventually go away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feedback! migration-guide-2.0.0-beta5.md perhaps?

- "command line interface"
- "command line"
- "System.CommandLine"
ms.topic: how-to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a how to, I would leave it blank for now.

Suggested change
ms.topic: how-to


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This article also isn't really a how to in the traditional sense. It just sort of plops a single snippet of code down and has some sub sections on what I assume are parameter options? But these descriptions don't really explain the options. For example, what does ResponseFileTokenReplacer actually do? Why would someone use it?

I would rewrite this to have a better "how to" approach:

  • Configure the parser to do X
  • Configure the parser to do Y
  • Additional configuration options

ms.topic: how-to
---

## Help option
Copy link
Contributor

@adegeo adegeo Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be more descriptive, perhaps this? Also, H1, not H2.

Suggested change
## Help option
# Customize help output

@@ -5,5 +5,5 @@ ms.date: 05/22/2022
ms.topic: include
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should move to live with the commandline docs docs/standard/commandline/includes/scl-preview.md

Comment on lines +939 to +940
- name: How to
items:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have this opened up by default since it's the only collapsible child

Suggested change
- name: How to
items:
- name: How to
expanded: true
items:

href: ../standard/commandline/tab-completion.md
- name: Customize help
href: ../standard/commandline/help.md
- name: Design guidance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is down at the bottom, would it make more sense to have it above the how to area?


1. Create a folder named *scl* for the project, and then open a command prompt in the new folder.

1. Run the following command:

```dotnetcli
dotnet new console --framework net6.0
dotnet new console --framework net9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the version important? Can we just create a new .NET console app and things will work regardless? The previous release supported standard 2.0, is that still the case with beta 5? Does the code shown in here use some .NET 9-specific feature?

href: ../standard/commandline/use-middleware.md
- name: How to
items:
- name: Parse and invoke the result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, with all of these articles here under a How to section, if they're really how-to articles, it helps SEO if their file name is how-to-*.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants