11/14/2023 0 Comments Quotunrecognized command or argument oHere's an example of command-line input and the resulting output for the preceding example code: myapp -language not-a-languageĪrgument 'not-a-language' not recognized. "An option that that must be one of the values of a static list.") To specify a list of valid values for an option or argument, specify an enum as the option type or use FromAmong, as shown in the following example: var languageOption = new Option( In the following example, the value three would be passed to the app. It allows you to repeat an option but takes only the last value on the line. The same setting has a different effect if maximum argument arity is 1. This setting lets you enter the following command line. To allow multiple arguments without repeating the option name, set Option.AllowMultipleArgumentsPerToken to true. System.CommandLine automatically determines the argument arity based on the argument type: Argument typeīy default, when you call a command, you can repeat an option name to specify multiple arguments for an option that has maximum arity greater than one. You can explicitly set argument arity by using the Arity property, but in most cases that is not necessary. ?, -h, -help Show help and usage information The options section of this example's command help omits the -endpoint option. RootCommand.SetHandler((delayOptionValue, messageOptionValue) =>Ĭonsole.WriteLine($"-delay = ("-message", "An option whose argument is parsed as a string.") The command handler code displays the values of those options: var delayOption = new Optionĭescription: "An option whose argument is parsed as an int.", The option names include double-hyphen prefixes, in accordance with POSIX conventions. The following example creates two options and adds them to the root command. The innermost subcommand in this example can be invoked like this: myapp sub1 sub1aĪ command handler method typically has parameters, and the values can come from command-line options. Var sub1aCommand = new Command("sub1a", "Second level subcommand") Var sub1Command = new Command("sub1", "First-level subcommand") You can add subcommands as shown in the following example: var rootCommand = new RootCommand() Var rootCommand = new RootCommand("Sample command-line app") Ĭommands can have child commands, known as subcommands or verbs, and they can nest as many levels as you need. The simplest case for invoking your code, if you have an app with no subcommands, options, or arguments, would look like this: using System.CommandLine Define a root commandĮvery command-line app has a root command, which refers to the executable file itself. To build a complete application that illustrates these techniques, see the tutorial Get started with System.CommandLine.įor guidance on how to design a command-line app's commands, options, and arguments, see Design guidance. This article explains how to define commands, options, and arguments in command-line apps that are built with the System.CommandLine library. Microsoft makes no warranties, express or implied, with respect to the information provided here. Some information relates to prerelease product that may be substantially modified before it's released. System.CommandLine is currently in PREVIEW, and this documentation is for version 2.0 beta 4.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |