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 Run method to implement the command's functionality.
Subcommands classes are instantiated using the CommandLineParser, and follow the same rules as command line arguments classes. They can define command line arguments using the properties and constructor parameters, which will be the arguments for the command.
Commands can be defined in a single assembly, or multiple assemblies.
CommandManager(CommandOptions) | Initializes a new instance of the CommandManager class for the calling assembly. |
CommandManager(Assembly, CommandOptions) | Initializes a new instance of the CommandManager class. |
CommandManager(IEnumerableAssembly, CommandOptions) | Initializes a new instance of the CommandManager class. |
Options | Gets the options used by this instance. |
ParseResult | Gets the result of parsing the arguments for the last call to CreateCommand. |
CreateCommand | Finds and instantiates the subcommand using the arguments from GetCommandLineArgs, using the first argument for the command name. If that fails, writes error and usage information. |
CreateCommand(String, Int32) | Finds and instantiates the subcommand with the name from the first argument, or if that fails, writes error and usage information. |
CreateCommand(String, String, Int32) | 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 the commands. |
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 GetCommandLineArgs method, using the first argument as the command name. If it succeeds, runs the command. If it fails, writes error and usage information. |
RunCommand(String, Int32) | 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, String, Int32) | 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 GetCommandLineArgs 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(String, Int32) | 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, Int32) | 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. |