Show / Hide Table of Contents

Class CommandBase

Base class for all command implementations

Inheritance
object
CommandBase
AsynchronousCommand
SynchronousCommand
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.CommandsFramework
Assembly: Benday.CommandsFramework.dll
Syntax
public abstract class CommandBase

Constructors

| Edit this page View Source

CommandBase(CommandExecutionInfo, ITextOutputProvider)

Constructor

Declaration
public CommandBase(CommandExecutionInfo info, ITextOutputProvider outputProvider)
Parameters
Type Name Description
CommandExecutionInfo info

Execution information for the requested command

ITextOutputProvider outputProvider

Output provider

Exceptions
Type Condition
ArgumentNullException

Fields

| Edit this page View Source

_OutputProvider

Declaration
protected readonly ITextOutputProvider _OutputProvider
Field Value
Type Description
ITextOutputProvider

Properties

| Edit this page View Source

Arguments

Arguments and values for the command. These are the combination of the argument definitions with the values from the command line. The values are set when the command is executed.

Declaration
public ArgumentCollection Arguments { get; }
Property Value
Type Description
ArgumentCollection
| Edit this page View Source

Description

Human readable description of this command

Declaration
public string Description { get; }
Property Value
Type Description
string
| Edit this page View Source

ExecutionInfo

Property for accessing the raw execution info for the command

Declaration
public CommandExecutionInfo ExecutionInfo { get; }
Property Value
Type Description
CommandExecutionInfo
| Edit this page View Source

IsQuietMode

Is this command running in quiet mode? Quiet mode suppresses the output written by WriteLine(). It is set by the reserved 'quiet' argument and is applied automatically to commands that are run by another command.

Declaration
public bool IsQuietMode { get; }
Property Value
Type Description
bool

Methods

| Edit this page View Source

CreateCommand<T>(Action<Dictionary<string, string>>?, bool)

Creates another command so that its logic can be reused from inside this command. The new command shares this command's program options, configuration and output provider, and runs in quiet mode by default so that it does not write over the calling command's output. The command is created but not run -- use ExecuteCommand() or ExecuteCommandAsync() to create and run it in one step.

Declaration
protected T CreateCommand<T>(Action<Dictionary<string, string>>? configureArguments = null, bool quiet = true) where T : CommandBase
Parameters
Type Name Description
Action<Dictionary<string, string>> configureArguments

Callback for populating the arguments for the command

bool quiet

Run the command in quiet mode. Defaults to true.

Returns
Type Description
T

The new command instance

Type Parameters
Name Description
T

Type of the command to create

Exceptions
Type Condition
KnownException

Thrown when the command type cannot be used

| Edit this page View Source

DisplayUsage()

Displays the command usage description

Declaration
protected virtual void DisplayUsage()
| Edit this page View Source

DisplayUsage(StringBuilder)

Adds the command usage description to the provided string builder

Declaration
protected void DisplayUsage(StringBuilder builder)
Parameters
Type Name Description
StringBuilder builder

StringBuilder instance

| Edit this page View Source

DisplayValidationSummary(List<IArgument>)

Creates and displays the validation summary when there are failed argument validations

Declaration
protected virtual void DisplayValidationSummary(List<IArgument> invalidArguments)
Parameters
Type Name Description
List<IArgument> invalidArguments

Collection of invalid arguments

| Edit this page View Source

ExecuteCommandAsync<T>(Action<Dictionary<string, string>>?, bool)

Creates another command, validates it, and runs it asynchronously. The command instance is returned so that results can be read back off it. Unlike running a command from the command line, a validation failure here throws rather than printing the usage information, because the calling command needs to know that the command did not run.

Declaration
protected Task<T> ExecuteCommandAsync<T>(Action<Dictionary<string, string>>? configureArguments = null, bool quiet = true) where T : AsynchronousCommand
Parameters
Type Name Description
Action<Dictionary<string, string>> configureArguments

Callback for populating the arguments for the command

bool quiet

Run the command in quiet mode. Defaults to true.

Returns
Type Description
Task<T>

The command instance after it has run

Type Parameters
Name Description
T

Type of the command to run

Exceptions
Type Condition
KnownException

Thrown when the arguments for the command are not valid

| Edit this page View Source

ExecuteCommand<T>(Action<Dictionary<string, string>>?, bool)

Creates another command, validates it, and runs it. The command instance is returned so that results can be read back off it. Unlike running a command from the command line, a validation failure here throws rather than printing the usage information, because the calling command needs to know that the command did not run.

Declaration
protected T ExecuteCommand<T>(Action<Dictionary<string, string>>? configureArguments = null, bool quiet = true) where T : SynchronousCommand
Parameters
Type Name Description
Action<Dictionary<string, string>> configureArguments

Callback for populating the arguments for the command

bool quiet

Run the command in quiet mode. Defaults to true.

Returns
Type Description
T

The command instance after it has run

Type Parameters
Name Description
T

Type of the command to run

Exceptions
Type Condition
KnownException

Thrown when the arguments for the command are not valid

| Edit this page View Source

GetArgValueOrRequiredConfigValue(string, string)

Declaration
public string GetArgValueOrRequiredConfigValue(string argumentName, string configValueName)
Parameters
Type Name Description
string argumentName
string configValueName
Returns
Type Description
string
| Edit this page View Source

GetArguments()

Get the argument definitions for the command execution. These are used to validate the execution but do not have any actual values.

Declaration
public virtual ArgumentCollection GetArguments()
Returns
Type Description
ArgumentCollection
| Edit this page View Source

SetValuesFromExecutionInfo()

Reads the arguments from the execution info and sets the values on to the argument definitions for the command. For arguments marked with FromConfig(), values are loaded from configuration with command line taking precedence.

Declaration
protected virtual void SetValuesFromExecutionInfo()
| Edit this page View Source

Validate()

Validate the arguments provided using the required argument definition for the command.

Declaration
protected virtual List<IArgument> Validate()
Returns
Type Description
List<IArgument>

List of invalid arguments

| Edit this page View Source

WriteLine()

Write a new line to the output provider. Does nothing in quiet mode.

Declaration
protected virtual void WriteLine()
| Edit this page View Source

WriteLine(string)

Write a message to the output provider. Does nothing in quiet mode.

Declaration
protected virtual void WriteLine(string text)
Parameters
Type Name Description
string text

Message to write

  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com