CommandManager Class

Provides functionality to find and instantiate subcommands.

Definition

Namespace: Ookii.CommandLine.Commands
Assembly: Ookii.CommandLine (in Ookii.CommandLine.dll) Version: 4.0.0+bb7ed9a8fdfd1cb21824750a8cf508863ad15086
C#
public class CommandManager
Inheritance
Object    CommandManager

Remarks

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.

Commands can be defined in a single assembly, or in multiple assemblies.

  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.

Constructors

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.

Properties

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.

Methods

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.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows 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.
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
GetUsage Gets a string with the usage help with a list of all the commands.
MemberwiseCloneCreates 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(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(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.
ToStringReturns a string that represents the current object.
(Inherited from Object)
WriteUsage Writes usage help with a list of all the commands.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also