共用方式為


Command Class

Definition

Represents a specific action that the application performs.

public ref class Command : System::CommandLine::Symbol, System::Collections::IEnumerable
public class Command : System.CommandLine.Symbol, System.Collections.IEnumerable
type Command = class
    inherit Symbol
    interface IEnumerable
Public Class Command
Inherits Symbol
Implements IEnumerable
Inheritance
Command
Derived
Implements

Remarks

Use the Command object for actions that correspond to a specific string (the command name). See RootCommand for simple applications that only have one action. For example, dotnet run uses run as the command.

Constructors

Name Description
Command(String, String)

Initializes a new instance of the Command class.

Properties

Name Description
Action

Gets or sets the CommandLineAction for the Command. The handler represents the action that will be performed when the Command is invoked.

Aliases

Gets the unique set of strings that can be used on the command line to specify the command.

Arguments

Represents all of the arguments for the command.

Children

Gets the child symbols.

Description

Gets or sets the description of the symbol.

(Inherited from Symbol)
Hidden

Gets or sets a value indicating whether the symbol is hidden.

(Inherited from Symbol)
Name

Gets the name of the symbol.

(Inherited from Symbol)
Options

Represents all of the options for the command, inherited options that have been applied to any of the command's ancestors.

Parents

Gets the parent symbols.

(Inherited from Symbol)
Subcommands

Represents all of the subcommands for the command.

TreatUnmatchedTokensAsErrors

Gets or sets a value that indicates whether unmatched tokens should be treated as errors. For example, if set to true and an extra command or argument is provided, validation will fail.

Validators

Validators to the command. Validators can be used to create custom validation logic.

Methods

Name Description
Add(Argument)

Adds a Argument to the command.

Add(Command)

Adds a Command to the command.

Add(Option)

Adds a Option to the command.

GetCompletions(CompletionContext)

Gets completions for the symbol.

Parse(IReadOnlyList<String>, ParserConfiguration)

Parses an array strings using the command.

Parse(String, ParserConfiguration)

Parses a command line string value using the command.

SetAction(Action<ParseResult>)

Sets a synchronous action to be run when the command is invoked.

SetAction(Func<ParseResult,CancellationToken,Task<Int32>>)

Sets an asynchronous action when the command is invoked.

SetAction(Func<ParseResult,CancellationToken,Task>)

Sets an asynchronous action to be run when the command is invoked.

SetAction(Func<ParseResult,Int32>)

Sets a synchronous action to be run when the command is invoked.

SetAction(Func<ParseResult,Task<Int32>>)

Sets an asynchronous action to be run when the command is invoked.

SetAction(Func<ParseResult,Task>)

Sets an asynchronous action to be run when the command is invoked.

ToString()

Returns a string that represents the current object.

(Inherited from Symbol)

Explicit Interface Implementations

Name Description
IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

Applies to