Command-line-api: docs: add example of AddArgument

Created on 18 Dec 2020  路  2Comments  路  Source: dotnet/command-line-api

The documentation doesn't include an example of AddArgument.

I'm actually looking how I can collect a bunch of arguments that are after --.
For example: ./my-command --option1 value1 -- any additional arguments.
How can I get a string[] that contains: "any", "additional", "arguments"?

cc @Keboo @jonsequitur

Area-Documentation needs documentation question

All 2 comments

@tmat I believe what you are looking for is the unparsed tokens on the ParseResult. Something like this:
C# [Fact] public void Can_retrieve_unparsed_tokens() { var rootCommand = new RootCommand("my-command") { new Option<string>("--option1"), }; rootCommand.TreatUnmatchedTokensAsErrors = false; var result = rootCommand.Parse("my-command --option1 value1 -- any additional arguments"); result.UnparsedTokens.Should().BeEquivalentTo("any", "additional", "arguments"); }

One additional point: TreatUnmatchedTokensAsErrors isn't necessary here. The behavior of -- is always enabled.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitfool picture gitfool  路  3Comments

anreton picture anreton  路  5Comments

urig picture urig  路  6Comments

SirJosh3917 picture SirJosh3917  路  3Comments

mariopasquali picture mariopasquali  路  4Comments