var countOption = new Option("--count", () => 1, "The number of times to repeat the message");
var parser = new CommandLineParser(); var result = parser.Parse(args); if (result.HasErrors) { Console.WriteLine(result.ErrorText); return; } var count = result.GetValueOrDefault("--count", 1); var message = result.GetArgument(0); for (int i = 0; i < count; i++) { Console.WriteLine(message); }
var app = new CommandLineApplication(); app.Command("build", buildCmd => { buildCmd.Description = "Build a project"; var projectOption = new OptionThis code creates a command-line application with a subcommand called "build". The subcommand takes an optional "--project" option, which specifies the path to a project file. When the "build" command is executed, the code retrieves the value of the "--project" option and prints a message indicating that the project is being built. Package library: `CommandLineApplication`("--project", "The path to the project file"); buildCmd.AddOption(projectOption); buildCmd.OnExecute(() => { var projectPath = projectOption.Value(); Console.WriteLine($"Building project at {projectPath}..."); }); }); app.Execute(args);