### Full Custom Services Example Source: https://natemcmaster.github.io/CommandLineUtils/docs/advanced/dependency-injection.html This example demonstrates the complete setup for using custom services with dependency injection, including service registration, convention setup, and service invocation. ```csharp [Command(Name = "di", Description = "Dependency Injection sample project")] [HelpOption] class Program { public static int Main(string[] args) { var services = new ServiceCollection() .AddSingleton() .AddSingleton(PhysicalConsole.Singleton) .BuildServiceProvider(); var app = new CommandLineApplication(); app.Conventions .UseDefaultConventions() .UseConstructorInjection(services); return app.Execute(args); } private readonly IMyService _myService; public Program(IMyService myService) { _myService = myService; } private void OnExecute() { _myService.Invoke(); } } ``` -------------------------------- ### Full Generic Host DI Example Source: https://natemcmaster.github.io/CommandLineUtils/docs/advanced/generic-host.html A complete example demonstrating dependency injection with the generic host and command line parsing. It includes service configuration, logging, and custom service implementations. ```csharp // Copyright (c) Nate McMaster. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace CustomServices { #region Program [Command(Name = "di", Description = "Dependency Injection sample project")] class Program { [Argument(0, Description = "your name")] private string Name { get; } = "dependency injection"; [Option("-l|--language", Description = "your desired language")] [AllowedValues("english", "spanish", IgnoreCase = true)] public string Language { get; } = "english"; public static async Task Main(string[] args) { return await new HostBuilder() .ConfigureLogging((context, builder) => { builder.AddConsole(); }) .ConfigureServices((context, services) => { services.AddSingleton() .AddSingleton(PhysicalConsole.Singleton); }) .RunCommandLineApplicationAsync(args); } private readonly ILogger _logger; private readonly IGreeter _greeter; public Program(ILogger logger, IGreeter greeter) { _logger = logger; _greeter = greeter; _logger.LogInformation("Constructed!"); } private void OnExecute() { _greeter.Greet(Name, Language); } } #endregion #region IGreeter interface IGreeter { void Greet(string name, string language); } #endregion #region Greeter class Greeter : IGreeter { private readonly IConsole _console; private readonly ILogger _logger; public Greeter(ILogger logger, IConsole console) { _logger = logger; _console = console; _logger.LogInformation("Constructed!"); } public void Greet(string name, string language = "english") { string greeting; switch (language) { case "english": greeting = "Hello {0}"; break; case "spanish": greeting = "Hola {0}"; break; default: throw new InvalidOperationException("validation should have caught this"); } _console.WriteLine(greeting, name); } } #endregion } ``` -------------------------------- ### Quick Example: .NET Command Line Application Source: https://natemcmaster.github.io/CommandLineUtils/index.html This example demonstrates a basic .NET command line application using CommandLineUtils. It includes argument parsing, validation, and password masking. ```csharp using McMaster.Extensions.CommandLineUtils; using System; using System.ComponentModel.DataAnnotations; class Program { public static int Main(string[] args) => CommandLineApplication.Execute(args); [Option("-n")] [Range(0, 10)] [Required] public int Count { get; } public void OnExecute() { for (var i = 0; i < Count; i ++) { Prompt.GetPassword("Enter your password: "); } } } ``` -------------------------------- ### Response File Content Example Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html Example content for a response file, where each line represents a command-line argument or option. ```text Completed the Boston marathon --tag major --tag fitness ``` -------------------------------- ### Example Command Line Source: https://natemcmaster.github.io/CommandLineUtils/docs/options.html Illustrates how a command line string can be parsed into options and arguments. ```text mycommand.exe abc --verbose --path:logs/ --message=Hello xyz ``` -------------------------------- ### Equivalent Command Line Execution Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html This demonstrates the equivalent command-line execution for the combined arguments example. ```text done "Completed the Boston marathon" --tag major --tag fitness __ ``` -------------------------------- ### Using Response Files with Sub-commands Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html This example shows how to use a response file in combination with sub-commands. ```text done list @input.txt __ ``` -------------------------------- ### Example Command Line Source: https://natemcmaster.github.io/CommandLineUtils/docs/arguments.html Illustrates a command line invocation with a fixed option and multiple file arguments. ```bash cat -b 123 file1.txt file2.txt file3.txt ``` -------------------------------- ### Combining Response Files with Other Arguments Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html This example shows how to pass a response file in combination with other command-line arguments. ```text done "Completed the Boston marathon" @input.txt __ ``` -------------------------------- ### Arguments Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Gets the required command-line arguments for the application. ```csharp public IReadOnlyList Arguments { get; }__ ``` -------------------------------- ### Generic Host Builder Configuration Source: https://natemcmaster.github.io/CommandLineUtils/docs/advanced/generic-host.html Shows the initial setup for configuring a generic host builder, including logging. ```csharp return await new HostBuilder() .ConfigureLogging((context, builder) => { builder.AddConsole(); }) .ConfigureServices((context, services) => { services.AddSingleton() .AddSingleton(PhysicalConsole.Singleton); ``` -------------------------------- ### HelpOption Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets help option metadata if it is defined for the command. ```csharp HelpOptionMetadata? HelpOption { get; } ``` -------------------------------- ### Commands Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Gets the subcommands available for the application. ```csharp public IReadOnlyCollection Commands { get; }__ ``` -------------------------------- ### Command Line Execution Example Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html Standard command-line execution without using a response file. ```bash myapp.exe @args.txt ``` -------------------------------- ### Options Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets metadata for all options defined on the command model. ```csharp IReadOnlyList Options { get; } ``` -------------------------------- ### VersionOption Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets version option metadata if it is defined for the command. ```csharp VersionOptionMetadata? VersionOption { get; } ``` -------------------------------- ### Prompt Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.html Utilities for getting input from an interactive console. ```APIDOC ## Class: Prompt ### Description Utilities for getting input from an interactive console. ### Usage ```csharp var response = Prompt.GetString("Enter your name:"); ``` ``` -------------------------------- ### Example of Response File Usage Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html Demonstrates how to use a response file to pass arguments to an application. The response file content is parsed as if each line were a separate command-line argument. ```bash done @input.txt ``` -------------------------------- ### Basic Console App with Attributes Source: https://natemcmaster.github.io/CommandLineUtils/docs/intro.html This example shows how to use attributes to define command-line options and handlers. Ensure the `System.Console` and `McMaster.Extensions.CommandLineUtils` namespaces are imported. ```csharp using System; using McMaster.Extensions.CommandLineUtils; public class Program { public static int Main(string[] args) => CommandLineApplication.Execute(args); [Option(Description = "The subject")] public string Subject { get; } private void OnExecute() { var subject = Subject ?? "world"; Console.WriteLine($"Hello {subject}!"); } } ``` -------------------------------- ### Description Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Sets or gets the description of the command, which appears in the help text. ```csharp public string? Description { get; set; }__ ``` -------------------------------- ### Basic Console App with Builder Pattern Source: https://natemcmaster.github.io/CommandLineUtils/docs/intro.html This example demonstrates using the builder pattern to configure command-line options and handlers. It requires importing `System` and `McMaster.Extensions.CommandLineUtils` namespaces. ```csharp using System; using McMaster.Extensions.CommandLineUtils; public class Program { public static int Main(string[] args) { var app = new CommandLineApplication(); app.HelpOption(); var subject = app.Option("-s|--subject ", "The subject", CommandOptionType.SingleValue); subject.DefaultValue = "world"; app.OnExecute(() => { Console.WriteLine($"Hello {subject.Value()}!"); return 0; }); return app.Execute(args); } } ``` -------------------------------- ### SelectedCommand Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Abstractions.ParseResult.html Gets or sets the application or subcommand that matches the command-line arguments. ```APIDOC ## SelectedCommand ### Description Gets or sets the application or subcommand that matches the command line arguments. ### Property Value (CommandLineApplication) ``` -------------------------------- ### SelectedCommand Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Abstractions.ParseResult.html Gets or sets the CommandLineApplication that corresponds to the parsed command-line arguments. ```csharp public CommandLineApplication SelectedCommand { get; set; } ``` -------------------------------- ### Basic Generic Host Integration Source: https://natemcmaster.github.io/CommandLineUtils/docs/advanced/generic-host.html A minimal sample demonstrating generic host integration with command line parsing. It shows how to use IHostingEnvironment and command line options. ```csharp // Copyright (c) Nate McMaster. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; using Microsoft.Extensions.Hosting; class Program { static Task Main(string[] args) => new HostBuilder() .RunCommandLineApplicationAsync(args); [Option] public int Port { get; } = 8080; private IHostEnvironment _env; public Program(IHostEnvironment env) { _env = env; } private void OnExecute() { Console.WriteLine($"Starting on port {Port}, env = {_env.EnvironmentName}"); } } ``` -------------------------------- ### Get Password Input from Console Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Prompt.html Use this method to securely get a password from the user. Input is masked with asterisks. Customizable prompt text and colors are supported. ```csharp public static string GetPassword(string prompt, ConsoleColor? promptColor = null, ConsoleColor? promptBgColor = null) ``` -------------------------------- ### OptionHelp Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Gets the command option configured to display help text, typically set by calling HelpOption(string). ```csharp public CommandOption? OptionHelp { get; }__ ``` -------------------------------- ### NoValue Option Example Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOptionType.html Demonstrates an option that is present only as a flag and does not accept any associated value. ```text --no-commit ``` -------------------------------- ### Install CommandLineUtils via dotnet CLI Source: https://natemcmaster.github.io/CommandLineUtils/docs/intro.html Use this command in your terminal to add the CommandLineUtils NuGet package to your project. ```bash dotnet add package McMaster.Extensions.CommandLineUtils ``` -------------------------------- ### SubcommandMetadata.SubcommandType Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.SubcommandMetadata.html Gets the type of the subcommand. ```csharp public Type SubcommandType { get; } ``` -------------------------------- ### Response File Content for List Command Source: https://natemcmaster.github.io/CommandLineUtils/docs/response-file-parsing.html This is an example of a response file that can be used with the `list` command, specifying values for the `Tags` option. ```text list --tag major --tag fitness __ ``` -------------------------------- ### SingleOrNoValue Option Examples Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOptionType.html Shows how an option can be used with or without a value. When a value is provided, it must be attached using '=' or ':' ```text --log ``` ```text --log:verbose ``` -------------------------------- ### MultipleValue Option Example Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOptionType.html Illustrates how to use an option that can be specified multiple times. Each occurrence adds a value. ```text --letter A --letter B --letter C ``` -------------------------------- ### GetHelpText Method Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Generates help text that describes how to use the command. Call this to display usage information to the user. ```csharp public virtual string GetHelpText()__ ``` -------------------------------- ### ModelType Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets the type of the model that this provider handles. ```csharp Type ModelType { get; } ``` -------------------------------- ### PhysicalConsole Out Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.PhysicalConsole.html Gets the text writer for the output stream. ```csharp public TextWriter Out { get; } ``` -------------------------------- ### Initialize CommandLineApplication with Console Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication-1.html Create a CommandLineApplication instance providing only an IConsole implementation. The working directory will be determined by the environment. ```csharp public CommandLineApplication(IConsole console)__ ``` -------------------------------- ### PhysicalConsole In Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.PhysicalConsole.html Gets the text reader for the input stream. ```csharp public TextReader In { get; } ``` -------------------------------- ### CommandOption Validators Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Gets a collection of validators for the option. ```csharp public ICollection Validators { get; } ``` -------------------------------- ### ShowHelp() Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Displays the full help information for the command-line application. ```APIDOC ## ShowHelp() ### Description Show full help. ### Method Signature ```csharp public void ShowHelp() ``` ``` -------------------------------- ### CommandOption OptionType Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Gets the type of the command-line option. ```csharp public CommandOptionType OptionType { get; } ``` -------------------------------- ### CommandLineApplication Constructors Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication-1.html Provides information on how to initialize a new instance of the CommandLineApplication class. ```APIDOC ## CommandLineApplication() ### Description Initializes a new instance of CommandLineApplication. ### Code ```csharp public CommandLineApplication() ``` ``` ```APIDOC ## CommandLineApplication(IConsole) ### Description Initializes a new instance of CommandLineApplication. ### Parameters - **console** (IConsole) - The console implementation to use. ### Code ```csharp public CommandLineApplication(IConsole console) ``` ``` ```APIDOC ## CommandLineApplication(IConsole, string) ### Description Initializes a new instance of CommandLineApplication. ### Parameters - **console** (IConsole) - The console implementation to use. - **workingDirectory** (string) - The current working directory. ### Code ```csharp public CommandLineApplication(IConsole console, string workingDirectory) ``` ``` ```APIDOC ## CommandLineApplication(IHelpTextGenerator, IConsole, string) ### Description This constructor is obsolete and will be removed in a future version. The recommended replacement is CommandLineApplication(IHelpTextGenerator, IConsole, string) Initializes a new instance of CommandLineApplication. ### Parameters - **helpTextGenerator** (IHelpTextGenerator) - The help text generator to use. - **console** (IConsole) - The console implementation to use. - **workingDirectory** (string) - The current working directory. ### Code ```csharp public CommandLineApplication(IHelpTextGenerator helpTextGenerator, IConsole console, string workingDirectory) ``` ``` -------------------------------- ### Initialize CommandLineApplication with Console and Working Directory Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication-1.html Instantiate CommandLineApplication with a specific IConsole implementation and working directory. This allows for explicit control over the application's environment. ```csharp public CommandLineApplication(IConsole console, string workingDirectory)__ ``` -------------------------------- ### Initialize CommandLineApplication with Custom Dependencies Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication-1.html Instantiate CommandLineApplication with custom IHelpTextGenerator, IConsole, and working directory. This constructor is obsolete and a newer version is recommended. ```csharp public CommandLineApplication(IHelpTextGenerator helpTextGenerator, IConsole console, string workingDirectory)__ ``` -------------------------------- ### Show Full Help Text Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Displays the full help text for the command line application. ```csharp public void ShowHelp() ``` -------------------------------- ### CommandInfo Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets metadata about the command itself, including its name and description. ```csharp CommandMetadata? CommandInfo { get; } ``` -------------------------------- ### Install CommandLineUtils via Package Manager Console Source: https://natemcmaster.github.io/CommandLineUtils/docs/intro.html Use this command in the Package Manager Console to add the CommandLineUtils NuGet package to your project. ```powershell Install-Package McMaster.Extensions.CommandLineUtils ``` -------------------------------- ### Arguments Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets metadata for all arguments defined on the command model. ```csharp IReadOnlyList Arguments { get; } ``` -------------------------------- ### PhysicalConsole ForegroundColor Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.PhysicalConsole.html Gets or sets the foreground color of the console. ```csharp public ConsoleColor ForegroundColor { get; set; } ``` -------------------------------- ### PhysicalConsole Error Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.PhysicalConsole.html Gets the text writer for the error stream. ```csharp public TextWriter Error { get; } ``` -------------------------------- ### Initialize CommandLineApplication with Default Constructor Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication-1.html Use the default constructor when no specific help text generator, console, or working directory is required. This is the simplest way to instantiate the class. ```csharp public CommandLineApplication()__ ``` -------------------------------- ### PhysicalConsole BackgroundColor Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.PhysicalConsole.html Gets or sets the background color of the console. ```csharp public ConsoleColor BackgroundColor { get; set; } ``` -------------------------------- ### GetHelpText Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Generates the help text for the command, describing its usage. ```APIDOC ## GetHelpText() ### Description Produces help text describing command usage. ### Method Signature ```csharp public virtual string GetHelpText() ``` #### Returns string - The help text. ``` -------------------------------- ### Conventions Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Gets a builder that can be used to apply conventions to the command-line application. ```csharp public IConventionBuilder Conventions { get; }__ ``` -------------------------------- ### ValidateHandler Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets the validate handler if one is defined for the command (OnValidate). ```csharp IValidateHandler? ValidateHandler { get; } ``` -------------------------------- ### Custom Help Option Output Source: https://natemcmaster.github.io/CommandLineUtils/docs/help-text.html Demonstrates the help output when using a custom help option flag. ```text > MyApp.exe --help Unrecognized option '--help' > MyApp.exe --my-custom-help-option Usage: MyApp.exe [options] Options: --my-custom-help-option Show help output ``` -------------------------------- ### Subcommands Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets metadata for subcommand types associated with the command model. ```csharp IReadOnlyList Subcommands { get; } ``` -------------------------------- ### RunCommandLineApplicationAsync(IHostBuilder, string[], Action>, CancellationToken) Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostBuilderExtensions.html Runs an instance of TApp using CommandLineApplication to provide command-line parsing on the given arguments. This method should be the primary approach taken for command-line applications. ```APIDOC ## RunCommandLineApplicationAsync(IHostBuilder, string[], Action>, CancellationToken) ### Description Runs an instance of `TApp` using CommandLineApplication to provide command line parsing on the given `args`. This method should be the primary approach taken for command line applications. ### Method `public static Task RunCommandLineApplicationAsync(this IHostBuilder hostBuilder, string[] args, Action> configure, CancellationToken cancellationToken = default) where TApp : class` ### Parameters #### Path Parameters - **hostBuilder** (IHostBuilder) - This instance - **args** (string[]) - The command line arguments - **configure** (Action>) - The delegate to configure the application - **cancellationToken** (CancellationToken) - A cancellation token ### Returns Task A task whose result is the exit code of the application ### Type Parameters - **TApp** - The type of the command line application implementation ``` -------------------------------- ### UseCommandLineApplication(IHostBuilder, string[], Action>) Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostBuilderExtensions.html Configures an instance of TApp using CommandLineApplication to provide command-line parsing on the given arguments. ```APIDOC ## UseCommandLineApplication(IHostBuilder, string[], Action>) ### Description Configures an instance of `TApp` using CommandLineApplication to provide command line parsing on the given `args`. ### Method `public static IHostBuilder UseCommandLineApplication(this IHostBuilder hostBuilder, string[] args, Action> configure) where TApp : class` ### Parameters #### Path Parameters - **hostBuilder** (IHostBuilder) - This instance - **args** (string[]) - The command line arguments - **configure** (Action>) - The delegate to configure the application ### Returns IHostBuilder IHostBuilder ### Type Parameters - **TApp** - The type of the command line application implementation ``` -------------------------------- ### VersionOptionMetadata VersionGetter Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.VersionOptionMetadata.html Represents a delegate to get the version from a member, if applicable. ```csharp public Func? VersionGetter { get; init; } ``` -------------------------------- ### ArgumentMetadata PropertyType Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ArgumentMetadata.html Gets the CLR type of the property. This property is read-only. ```csharp public Type PropertyType { get; } ``` -------------------------------- ### UseCommandLineApplication(IHostBuilder, string[]) Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostBuilderExtensions.html Configures an instance of TApp using CommandLineApplication to provide command-line parsing on the given arguments. ```APIDOC ## UseCommandLineApplication(IHostBuilder, string[]) ### Description Configures an instance of `TApp` using CommandLineApplication to provide command line parsing on the given `args`. ### Method `public static IHostBuilder UseCommandLineApplication(this IHostBuilder hostBuilder, string[] args) where TApp : class` ### Parameters #### Path Parameters - **hostBuilder** (IHostBuilder) - This instance - **args** (string[]) - The command line arguments ### Returns IHostBuilder IHostBuilder ### Type Parameters - **TApp** - The type of the command line application implementation ``` -------------------------------- ### Execute Method Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matches arguments, and invokes OnExecute or OnExecuteAsync. Use this to run your application. ```csharp public static int Execute(params string[] args) where TApp : class__ ``` -------------------------------- ### ConsoleReporter.Console Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.ConsoleReporter.html Gets the console instance used by the reporter for writing output. ```csharp protected IConsole Console { get; } ``` -------------------------------- ### WorkingDirectory Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Abstractions.CommandLineContext.html Gets or sets the current working directory for the application. Defaults to the current system directory. This property cannot be null and must be an absolute file path. ```csharp public string WorkingDirectory { get; protected set; }__ ``` -------------------------------- ### CommandOption LongName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Gets the long name of the option, used with '--'. ```csharp public string? LongName { get; set; } ``` -------------------------------- ### RunCommandLineApplicationAsync(IHostBuilder, string[], Action, CancellationToken) Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostBuilderExtensions.html Runs an instance of CommandLineApplication using the builder API to provide command-line parsing on the given arguments. ```APIDOC ## RunCommandLineApplicationAsync(IHostBuilder, string[], Action, CancellationToken) ### Description Runs an instance of CommandLineApplication using builder API to provide command line parsing on the given `args`. ### Method `public static Task RunCommandLineApplicationAsync(this IHostBuilder hostBuilder, string[] args, Action configure, CancellationToken cancellationToken = default)` ### Parameters #### Path Parameters - **hostBuilder** (IHostBuilder) - This instance - **args** (string[]) - The command line arguments - **configure** (Action) - The delegate to configure the application - **cancellationToken** (CancellationToken) - A cancellation token ### Returns Task A task whose result is the exit code of the application ``` -------------------------------- ### RunCommandLineApplicationAsync(IHostBuilder, string[], CancellationToken) Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostBuilderExtensions.html Runs an instance of TApp using CommandLineApplication to provide command-line parsing on the given arguments. This method should be the primary approach taken for command-line applications. ```APIDOC ## RunCommandLineApplicationAsync(IHostBuilder, string[], CancellationToken) ### Description Runs an instance of `TApp` using CommandLineApplication to provide command line parsing on the given `args`. This method should be the primary approach taken for command line applications. ### Method `public static Task RunCommandLineApplicationAsync(this IHostBuilder hostBuilder, string[] args, CancellationToken cancellationToken = default) where TApp : class` ### Parameters #### Path Parameters - **hostBuilder** (IHostBuilder) - This instance - **args** (string[]) - The command line arguments - **cancellationToken** (CancellationToken) - A cancellation token ### Returns Task A task whose result is the exit code of the application ### Type Parameters - **TApp** - The type of the command line application implementation ``` -------------------------------- ### GetOptions Method Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Retrieves all available command-line options for this command, including inherited ones. Use this to inspect the defined options. ```csharp public IEnumerable GetOptions()__ ``` -------------------------------- ### Execute(CommandLineContext) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matching Arguments to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. This overload uses a provided CommandLineContext. ```APIDOC ## Execute(CommandLineContext) ### Description Creates an instance of `TApp`, matching Arguments to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static int Execute(CommandLineContext context) where TApp : class ``` ### Parameters #### `context` CommandLineContext The execution context. ### Returns int The process exit code ### Type Parameters #### `TApp` A type that should be bound to the arguments. ### Exceptions #### InvalidOperationException Thrown when attributes are incorrectly configured. ### See Also OptionAttribute ArgumentAttribute HelpOptionAttribute VersionOptionAttribute ``` -------------------------------- ### ShowHelp(bool) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Displays the full help information for the command-line application, with an option to use a console pager. ```APIDOC ## ShowHelp(bool) ### Description Show full help. ### Method Signature ```csharp public void ShowHelp(bool usePager) ``` ### Parameters #### Path Parameters - **usePager** (bool) - Use a console pager to display help text, if possible. ``` -------------------------------- ### RunCommandLineApplicationAsync Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostExtensions.html Runs the application using a CommandLineApplication previously configured via UseCommandLineApplication. This method is an extension method for IHost. ```APIDOC ## RunCommandLineApplicationAsync(IHost, CancellationToken) ### Description Runs the app using the CommandLineApplication previously configured in UseCommandLineApplication(IHostBuilder, string[], Action>). ### Method `public static Task RunCommandLineApplicationAsync(this IHost host, CancellationToken cancellationToken = default)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```csharp // Example usage (assuming host is already configured) await host.RunCommandLineApplicationAsync(); ``` ### Response #### Success Response (Task) - Returns a Task that represents the asynchronous operation. The int value typically represents the exit code of the application. #### Response Example ```csharp // The Task will complete with the application's exit code. ``` ### Parameters #### Path Parameters - `host` (IHost) - Required - A program abstraction. - `cancellationToken` (CancellationToken) - Optional - Propagates notification that operations should be canceled. ``` -------------------------------- ### HelpTextGenerator Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Sets or gets the help text generator implementation to be used by the application. ```csharp public IHelpTextGenerator HelpTextGenerator { get; set; }__ ``` -------------------------------- ### FullName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Sets or gets the full name of the command, used in the help text. ```csharp public string? FullName { get; set; }__ ``` -------------------------------- ### Execute(IConsole, params string[]) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. This overload uses a provided IConsole and string array for arguments. ```APIDOC ## Execute(IConsole, params string[]) ### Description Creates an instance of `TApp`, matching `args` to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static int Execute(IConsole console, params string[] args) where TApp : class ``` ### Parameters #### `console` IConsole The console to use #### `args` string[] The arguments ### Returns int The process exit code ### Type Parameters #### `TApp` A type that should be bound to the arguments. ### Exceptions #### InvalidOperationException Thrown when attributes are incorrectly configured. ### See Also OptionAttribute ArgumentAttribute HelpOptionAttribute VersionOptionAttribute ``` -------------------------------- ### ClusterOptions Property Example Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Demonstrates how options can be clustered behind a single '-' delimiter when ClusterOptions is true. This property defaults to true unless an option with a short name of two or more characters is added. ```csharp -abcXyellow -abcX=yellow -abcX:yellow -abc -X=yellow -ab -cX=yellow -a -b -c -Xyellow -a -b -c -X yellow -a -b -c -X=yellow -a -b -c -X:yellow__ ``` ```csharp public bool ClusterOptions { get; set; }__ ``` -------------------------------- ### Error Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Sets or gets the TextWriter used to display generated error messages. ```csharp public TextWriter Error { get; set; }__ ``` -------------------------------- ### RunCommandLineApplicationAsync - HostExtensions Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostExtensions.html Runs a command-line application that has been configured using UseCommandLineApplication. This method is an extension for IHost and is suitable for executing console applications managed by the host. ```csharp public static Task RunCommandLineApplicationAsync(this IHost host, CancellationToken cancellationToken = default) ``` -------------------------------- ### Add Extended Help Text Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandAttribute.html Use ExtendedHelpText to append additional information to the end of the generated help text. This is useful for providing more detailed usage instructions or examples. ```csharp public string? ExtendedHelpText { get; set; } ``` -------------------------------- ### Default Help Output Source: https://natemcmaster.github.io/CommandLineUtils/docs/help-text.html Shows the default help text generated when the --help option is used. ```text > MyApp.exe --help Usage: MyApp.exe [options] Options: -?|-h|--help Show help output ``` -------------------------------- ### ValidationErrorHandler Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets the validation error handler if one is defined for the command (OnValidationError). ```csharp IValidationErrorHandler? ValidationErrorHandler { get; } ``` -------------------------------- ### ExecuteHandler Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets the execute handler if one is defined for the command (OnExecute or OnExecuteAsync). ```csharp IExecuteHandler? ExecuteHandler { get; } ``` -------------------------------- ### Option(string, string, CommandOptionType, Action, bool) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Adds a command-line option with a specified template, description, type, configuration action, and inheritance flag. ```APIDOC ## Option(string, string, CommandOptionType, Action, bool) ### Description Adds a command line option. ### Method Signature ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType, Action configuration, bool inherited) ``` #### Parameters * `template` string * `description` string * `optionType` CommandOptionType * `configuration` Action * `inherited` bool #### Returns CommandOption ``` -------------------------------- ### SubcommandMetadata.CommandName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.SubcommandMetadata.html Gets the command name. If not specified, it's derived from the type name. ```csharp public string? CommandName { get; init; } ``` -------------------------------- ### CommandLineApplicationExtensions Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.html Helper methods for CommandLineApplication. ```APIDOC ## Class: CommandLineApplicationExtensions ### Description Helper methods for CommandLineApplication. ### Usage ```csharp // Example usage would depend on specific extension methods. ``` ``` -------------------------------- ### ArgumentMetadata PropertyName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ArgumentMetadata.html Gets the name of the property this argument maps to. This property is read-only. ```csharp public string PropertyName { get; } ``` -------------------------------- ### UseCommandLineApplication with Generic Type and Action Source: https://natemcmaster.github.io/CommandLineUtils/api/Microsoft.Extensions.Hosting.HostBuilderExtensions.html Configures the host builder to use a specific command-line application type (TApp) with the provided arguments and an optional configuration delegate. This method returns the host builder for further configuration. ```csharp public static IHostBuilder UseCommandLineApplication(this IHostBuilder hostBuilder, string[] args, Action> configure) where TApp : class ``` -------------------------------- ### ArgumentMetadata DeclaringType Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ArgumentMetadata.html Gets the type that declares this property. This property is read-only after initialization. ```csharp public Type? DeclaringType { get; init; } ``` -------------------------------- ### ExecuteAsync(IConsole, params string[]) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. This overload uses a provided IConsole and string array for arguments. ```APIDOC ## ExecuteAsync(IConsole, params string[]) ### Description Creates an instance of `TApp`, matching `args` to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static Task ExecuteAsync(IConsole console, params string[] args) where TApp : class ``` ### Parameters #### `console` IConsole The console to use #### `args` string[] The arguments ### Returns Task The process exit code ### Type Parameters #### `TApp` A type that should be bound to the arguments. ### Exceptions #### InvalidOperationException Thrown when attributes are incorrectly configured. ### See Also OptionAttribute ArgumentAttribute HelpOptionAttribute VersionOptionAttribute ``` -------------------------------- ### Template Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.OptionAttributeBase.html Gets or sets the option template, which is parsed into short and long names. ```csharp public string? Template { get; set; } ``` -------------------------------- ### Configure Constructor Injection Convention Source: https://natemcmaster.github.io/CommandLineUtils/docs/advanced/dependency-injection.html Build the service provider and then configure the CommandLineApplication to use constructor injection by calling UseConstructorInjection with the service provider. ```csharp .BuildServiceProvider(); var app = new CommandLineApplication(); app.Conventions .UseDefaultConventions() .UseConstructorInjection(services); ``` -------------------------------- ### HelpOptionAttribute Constructors Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.HelpOptionAttribute.html Initializes a new instance of the HelpOptionAttribute class. ```APIDOC ## HelpOptionAttribute() ### Description Initializes a new HelpOptionAttribute with the template `-?|-h|--help`. ### Parameters None ### Returns A new instance of HelpOptionAttribute. ``` ```APIDOC ## HelpOptionAttribute(string template) ### Description Initializes a new HelpOptionAttribute. ### Parameters #### Parameters - **template** (string) - The string template. This is parsed into ShortName and LongName. ### Returns A new instance of HelpOptionAttribute. ``` -------------------------------- ### Get Model Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication-1.html Access the model instance associated with the command line application. ```csharp public TModel Model { get; } ``` -------------------------------- ### CommandOption ValueName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Gets or sets the name of the value(s) shown in help text. ```csharp public string? ValueName { get; set; } ``` -------------------------------- ### Option Method Overloads Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Methods to add a command-line option. Configure the option's template, description, type, and optional configuration action. ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType)__ ``` ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType, Action configuration)__ ``` ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType, Action configuration, bool inherited)__ ``` ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType, bool inherited)__ ``` -------------------------------- ### Show Root Command Full Name and Version Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Traverses up the parent hierarchy and displays the result of GetFullNameAndVersion(). ```csharp public void ShowRootCommandFullNameAndVersion() ``` -------------------------------- ### CommandOption SymbolName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Gets or sets an additional single-character symbol name for the option. ```csharp public string? SymbolName { get; set; } ``` -------------------------------- ### CommandOption ShortName Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Gets or sets the short name of the option, used with '-'. ```csharp public string? ShortName { get; set; } ``` -------------------------------- ### Option(string, string, CommandOptionType, Action) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Adds a command-line option with a specified template, description, type, and configuration action. ```APIDOC ## Option(string, string, CommandOptionType, Action) ### Description Adds a command-line option. ### Method Signature ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType, Action configuration) ``` #### Parameters * `template` string * `description` string * `optionType` CommandOptionType * `configuration` Action #### Returns CommandOption ``` -------------------------------- ### CommandOption Constructor Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandOption.html Initializes a new CommandOption with a template string and option type. ```csharp public CommandOption(string template, CommandOptionType optionType) ``` -------------------------------- ### ArgumentAttribute Order Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.ArgumentAttribute.html Gets or sets the order in which the argument is expected relative to other arguments. ```csharp public int Order { get; set; } ``` -------------------------------- ### ExecuteAsync(CommandLineContext, CancellationToken) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matching Arguments to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. This overload uses a provided CommandLineContext and CancellationToken. ```APIDOC ## ExecuteAsync(CommandLineContext, CancellationToken) ### Description Creates an instance of `TApp`, matching Arguments to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static Task ExecuteAsync(CommandLineContext context, CancellationToken cancellationToken = default) where TApp : class ``` ### Parameters #### `context` CommandLineContext The execution context. #### `cancellationToken` CancellationToken ### Returns Task The process exit code ### Type Parameters #### `TApp` A type that should be bound to the arguments. ### Exceptions #### InvalidOperationException Thrown when attributes are incorrectly configured. ### See Also OptionAttribute ArgumentAttribute HelpOptionAttribute VersionOptionAttribute ``` -------------------------------- ### Format(CommandOption) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.HelpText.DefaultHelpTextGenerator.html Generates the template string for displaying command options in help text. ```APIDOC ## Format(CommandOption) ### Description Generates the template string in the format "-{Symbol}|-{Short}|--{Long} <{Value}>" for display in help text. ### Method protected virtual string Format(CommandOption option) ### Parameters * `option` CommandOption - The command option to format. ``` -------------------------------- ### ExecuteAsync(params string[]) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. This overload takes only a string array for arguments. ```APIDOC ## ExecuteAsync(params string[]) ### Description Creates an instance of `TApp`, matching `args` to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static Task ExecuteAsync(params string[] args) where TApp : class ``` ### Parameters #### `args` string[] The arguments ### Returns Task The process exit code ### Type Parameters #### `TApp` A type that should be bound to the arguments. ### Exceptions #### InvalidOperationException Thrown when attributes are incorrectly configured. ### See Also OptionAttribute ArgumentAttribute HelpOptionAttribute VersionOptionAttribute ``` -------------------------------- ### Names Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Gets all names by which the command can be referenced, including its primary Name and any added aliases. ```csharp public IEnumerable Names { get; }__ ``` -------------------------------- ### Custom Help Text Generator Implementation Source: https://natemcmaster.github.io/CommandLineUtils/docs/help-text.html Provides a completely custom help text generation by implementing the IHelpTextGenerator interface. ```csharp class MyHelpTextGenerator : IHelpTextGenerator { public void Generate(CommandLineApplication application, TextWriter output) { output.WriteLine(@"To use this command, throw salt over your shoulder and spit twice."); } } class Program { public static int Main(string[] args) { var app = new CommandLineApplication(); app.HelpTextGenerator = new MyHelpTextGenerator(); return app.Execute(args); } } ``` -------------------------------- ### Name Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Sets or gets the short name of the command. For subcommands, this is the name used to invoke them. ```csharp public string? Name { get; set; }__ ``` -------------------------------- ### SpecialProperties Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ICommandMetadataProvider.html Gets property accessors for setting Parent, RemainingArgs, and Subcommand on the command model. ```csharp SpecialPropertiesMetadata? SpecialProperties { get; } ``` -------------------------------- ### Execute Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matches arguments, and invokes the OnExecute or OnExecuteAsync method. ```APIDOC ## Execute(params string[]) ### Description Creates an instance of `TApp`, matching `args` to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static int Execute(params string[] args) where TApp : class ``` #### Parameters * `args` string[] - The arguments #### Returns int - The process exit code #### Type Parameters * `TApp` - A type that should be bound to the arguments. #### Exceptions * `InvalidOperationException` - Thrown when attributes are incorrectly configured. ### See Also * OptionAttribute * ArgumentAttribute * HelpOptionAttribute * VersionOptionAttribute ``` -------------------------------- ### IHelpTextGenerator.Generate Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.HelpText.IHelpTextGenerator.html Generates help text for the command-line application and writes it to the provided TextWriter. ```APIDOC ## Generate(CommandLineApplication, TextWriter) ### Description Generates help text for the application. ### Method void Generate(CommandLineApplication application, TextWriter output) ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Request Example * None ### Response #### Success Response * None #### Response Example * None ``` -------------------------------- ### ArgumentMetadata Order Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.ArgumentMetadata.html Gets the order in which the argument is expected, relative to other arguments. This property is read-only. ```csharp public int Order { get; } ``` -------------------------------- ### UseDefaultHelpOption Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.ConventionBuilderExtensions.html Adds the --help option if a help flag is not already set. The default template is '-?|-h|--help'. Use this to ensure users can access help information for commands. ```csharp public static IConventionBuilder UseDefaultHelpOption(this IConventionBuilder builder, string template = "-?|-h|--help") ``` -------------------------------- ### DefaultMetadataResolver.Instance Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.SourceGeneration.DefaultMetadataResolver.html Gets the singleton instance of the default metadata resolver. This is the primary way to access the resolver. ```APIDOC ## DefaultMetadataResolver.Instance ### Description Gets the singleton instance of the default metadata resolver. ### Field Value DefaultMetadataResolver ``` -------------------------------- ### ConsoleReporter.IsVerbose Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.ConsoleReporter.html Gets or sets a value indicating whether verbose output messages are displayed. ```csharp public bool IsVerbose { get; set; } ``` -------------------------------- ### CommandArgument Name Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandArgument.html Gets or sets the name of the argument. This is used for identification and in help text. ```csharp public string? Name { get; set; } ``` -------------------------------- ### Default HelpOptionAttribute Constructor Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.HelpOptionAttribute.html Initializes a new instance of the HelpOptionAttribute class with the default template '-?|-h|--help'. This is the standard way to define the help option. ```csharp public HelpOptionAttribute() ``` -------------------------------- ### Options Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Provides access to all available command-line options for this command, including any inherited options. Use GetOptions() for a comprehensive list. ```csharp public IReadOnlyCollection Options { get; } ``` -------------------------------- ### LongVersionGetter Property Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Sets or gets a function that provides the long-form version string for display in help text. ```csharp public Func? LongVersionGetter { get; set; }__ ``` -------------------------------- ### ExecuteAsync(string[], CancellationToken) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. This overload uses a string array for arguments and a CancellationToken. ```APIDOC ## ExecuteAsync(string[], CancellationToken) ### Description Creates an instance of `TApp`, matching `args` to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists. ### Method Signature ```csharp public static Task ExecuteAsync(string[] args, CancellationToken cancellationToken = default) where TApp : class ``` ### Parameters #### `args` string[] The arguments #### `cancellationToken` CancellationToken ### Returns Task The process exit code ### Type Parameters #### `TApp` A type that should be bound to the arguments. ### Exceptions #### InvalidOperationException Thrown when attributes are incorrectly configured. ### See Also OptionAttribute ArgumentAttribute HelpOptionAttribute VersionOptionAttribute ``` -------------------------------- ### GetValidationResult for CommandOption Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Validation.AttributeValidator.html Gets the validation result for a command line option based on associated validation attributes. ```APIDOC ## GetValidationResult(CommandOption, ValidationContext) ### Description Gets the validation result for a command line option. ### Parameters - **option** (CommandOption) - The command line option to validate. - **context** (ValidationContext) - The context under which validation should be performed. ### Returns ValidationResult? - The validation result, or null if no validation is needed. ``` -------------------------------- ### HelpOptionAttributeConvention.Apply Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Conventions.HelpOptionAttributeConvention.html Applies the convention to set the help option based on the HelpOptionAttribute. ```APIDOC ## Apply(ConventionContext) ### Description Apply the convention. ### Method `public virtual void Apply(ConventionContext context)` ### Parameters #### Parameters - **context** (ConventionContext) - The context in which the convention is applied. ``` -------------------------------- ### GetValidationResult for CommandArgument Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.Validation.AttributeValidator.html Gets the validation result for a command line argument based on associated validation attributes. ```APIDOC ## GetValidationResult(CommandArgument, ValidationContext) ### Description Gets the validation result for a command line argument. ### Parameters - **argument** (CommandArgument) - The command line argument to validate. - **context** (ValidationContext) - The context under which validation should be performed. ### Returns ValidationResult? - The validation result, or null if no validation is needed. ``` -------------------------------- ### Option(string, string, CommandOptionType, bool) Source: https://natemcmaster.github.io/CommandLineUtils/api/McMaster.Extensions.CommandLineUtils.CommandLineApplication.html Adds a command-line option with a specified template, description, type, and inheritance flag. ```APIDOC ## Option(string, string, CommandOptionType, bool) ### Description Adds a command-line option. ### Method Signature ```csharp public CommandOption Option(string template, string description, CommandOptionType optionType, bool inherited) ``` #### Parameters * `template` string * `description` string * `optionType` CommandOptionType * `inherited` bool #### Returns CommandOption ```