Note
If you reuse the same CommandManager instance or CommandOptions
instance to create multiple commands, the ParseOptionsAttribute of one
command may affect the behavior of another.
public class CommandManager
Public Class CommandManager
Dim instance As CommandManager
public ref class CommandManager
Subcommands can be used to create applications that perform more than one operation, where each operation has its own set of command line arguments. For example, think of the dotnet executable, which has subcommands such as dotnet build and dotnet run.
For a program using subcommands, typically the first command line argument will be the name of the command, while the remaining arguments are arguments to the command. The CommandManager class provides functionality that makes creating an application like this easy.
A subcommand is created by creating a class that implements the ICommand interface, and applying the CommandAttribute attribute to it. Implement the ICommandRun method to implement the command's functionality.
Subcommand classes are instantiated using the CommandLineParser class, and follow the same rules as command line arguments classes, unless they implement the ICommandWithCustomParsing interface.
Subcommands can support asynchronous execution by implementing the IAsyncCommand or IAsyncCancelableCommand interface.
Commands can be defined in a single assembly, or in multiple assemblies.
CommandManager(CommandOptions) | Initializes a new instance of the CommandManager class for the assembly that is calling the constructor. |
CommandManager(Assembly, CommandOptions) | Initializes a new instance of the CommandManager class using the specified assembly. |
CommandManager(CommandProvider, CommandOptions) | Initializes a new instance of the CommandManager class using the specified CommandProvider. |
CommandManager(IEnumerableAssembly, CommandOptions) | Initializes a new instance of the CommandManager class using the specified assemblies. |
Options | Gets the options used by this instance. |
ParseResult | Gets the result of parsing the arguments for the last call to CreateCommand. |
ProviderKind | Gets the kind of CommandProvider used to supply the commands. |
CreateCommand | Finds and instantiates the subcommand using the arguments from the EnvironmentGetCommandLineArgs method, using the first argument for the command name. If that fails, writes error and usage information. |
CreateCommand(ReadOnlyMemoryString) | Finds and instantiates the subcommand with the name from the first argument, or if that fails, writes error and usage information. |
CreateCommand(String) | Finds and instantiates the subcommand with the name from the first argument, or if that fails, writes error and usage information. |
CreateCommand(String, ReadOnlyMemoryString) | Finds and instantiates the subcommand with the specified name, or if that fails, writes error and usage information. |
CreateCommand(String, String) | Finds and instantiates the subcommand with the specified name, or if that fails, writes error and usage information. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetApplicationDescription | Gets the application description that will optionally be included in the usage help. |
GetCommand | Gets the subcommand with the specified command name. |
GetCommands | Gets information about all the commands managed by this instance. |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
GetUsage | Gets a string with the usage help with a list of all the commands. |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
RunCommand | Finds and instantiates the subcommand using the arguments from the EnvironmentGetCommandLineArgs method, using the first argument as the command name. If it succeeds, runs the command. If it fails, writes error and usage information. |
RunCommand(ReadOnlyMemoryString) | Finds and instantiates the subcommand with the name from the first argument, and if it succeeds, runs it. If it fails, writes error and usage information. |
RunCommand(String) | Finds and instantiates the subcommand with the name from the first argument, and if it succeeds, runs it. If it fails, writes error and usage information. |
RunCommand(String, ReadOnlyMemoryString) | Finds and instantiates the subcommand with the specified name, and if it succeeds, runs it. If it fails, writes error and usage information. |
RunCommand(String, String) | Finds and instantiates the subcommand with the specified name, and if it succeeds, runs it. If it fails, writes error and usage information. |
RunCommandAsync | Finds and instantiates the subcommand using the arguments from the EnvironmentGetCommandLineArgs method, using the first argument as the command name. If it succeeds, runs the command asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(CancellationToken) | Finds and instantiates the subcommand using the arguments from the EnvironmentGetCommandLineArgs method, using the first argument as the command name. If it succeeds, runs the command asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(ReadOnlyMemoryString) | Finds and instantiates the subcommand with the name from the first argument, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(String) | Finds and instantiates the subcommand with the name from the first argument, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(ReadOnlyMemoryString, CancellationToken) | Finds and instantiates the subcommand with the name from the first argument, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(String, ReadOnlyMemoryString) | Finds and instantiates the subcommand with the specified name, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(String, String) | Finds and instantiates the subcommand with the specified name, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(String, CancellationToken) | Finds and instantiates the subcommand with the name from the first argument, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(String, ReadOnlyMemoryString, CancellationToken) | Finds and instantiates the subcommand with the specified name, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
RunCommandAsync(String, String, CancellationToken) | Finds and instantiates the subcommand with the specified name, and if it succeeds, runs it asynchronously. If it fails, writes error and usage information. |
ToString | Returns a string that represents the current object. (Inherited from Object) |
WriteUsage | Writes usage help with a list of all the commands. |