C# Class CommandLine.UI

Main class for interacting via the command-line. Handles the definition and parsing of command-line arguments, and the display of usage and help messages.
Afficher le fichier Open project: agardiner/hfmcmd

Méthodes publiques

Свойство Type Description
Definition Definition
Interrupted bool
IsRedirected bool

Protected Properties

Свойство Type Description
_log log4net.ILog

Méthodes publiques

Méthode Description
AddFlagArgument ( string key, string desc ) : FlagArgument

Convenience method for defining a new flag argument.

AddFlagArgument ( string key, string desc, Argument onParse ) : FlagArgument

Convenience method for defining a new flag argument.

AddKeywordArgument ( string key, string desc ) : KeywordArgument

Convenience method for defining a new keyword argument.

AddKeywordArgument ( string key, string desc, Argument onParse ) : KeywordArgument

Convenience method for defining a new keyword argument.

AddPositionalArgument ( string key, string desc ) : PositionalArgument

Convenience method for defining a new positional argument.

AddPositionalArgument ( string key, string desc, Argument onParse ) : PositionalArgument

Convenience method for defining a new positional argument.

ClassifyArguments ( IEnumerable args ) : int

Classifies the supplied list of arguments, returning a count of the number of positional arguments found.

ClearArguments ( ) : void

Clear existing arguments from the definition.

ClearLine ( ) : void

Clears the last text written to the console using Write. Note that this may be more than a single line of text, if the window width is less than the length of the string written.

DisplayTitle ( TextWriter console ) : void

Displays the application title, version etc.

DisplayUsage ( TextWriter console, object>.Dictionary args ) : void

Displays a usgae message, based on the allowed arguments and purpose represented by this class.

Parse ( IEnumerable args ) : object>.Dictionary

Parses the supplied set of arg strings using the list of Argument definitions maintained by this command-line UI instance.

ReadLine ( string prompt ) : string

For completeness - read a line of input from the console.

ReadPassword ( string prompt ) : string

Reads a password from the command-line, echoing * for each keypress.

RegisterCtrlHandler ( ) : Win32.Handler

This method registers this class as a handler for Ctrl-C etc events in the console. It returns a handle to the handler, which should be referenced via the following at the end of the program Main method: GC.KeepAlive(hr);

UI ( string help ) : System

Constructor; requires a purpose for the program whose args we are parsing.

WithColor ( ConsoleColor color, System.Action op ) : void

Performs the specified operation +op+ with the console color temporarily changed to +color+. On completion of the operation, the color is reset to the original color.

Write ( string line ) : void

Writes a partial line of text to the console, without moving to the next line.

WriteLine ( ) : void

Writes a blank line to the console.

WriteLine ( string text ) : void

Writes a line of text to the console, ensuring lines the same width as the console don't output an unnecessary new-line.

Méthodes protégées

Méthode Description
OutputArg ( Argument arg, TextWriter console ) : void

Private Methods

Méthode Description
CtrlHandler ( EInterruptTypes ctrlType ) : bool

Handler to receive control events, such as Ctrl-C and logoff and shutdown events. As a minimum, this logs the event, so that a record of why the process exited is maintained.

Method Details

AddFlagArgument() public méthode

Convenience method for defining a new flag argument.
public AddFlagArgument ( string key, string desc ) : FlagArgument
key string
desc string
Résultat FlagArgument

AddFlagArgument() public méthode

Convenience method for defining a new flag argument.
public AddFlagArgument ( string key, string desc, Argument onParse ) : FlagArgument
key string
desc string
onParse Argument
Résultat FlagArgument

AddKeywordArgument() public méthode

Convenience method for defining a new keyword argument.
public AddKeywordArgument ( string key, string desc ) : KeywordArgument
key string
desc string
Résultat KeywordArgument

AddKeywordArgument() public méthode

Convenience method for defining a new keyword argument.
public AddKeywordArgument ( string key, string desc, Argument onParse ) : KeywordArgument
key string
desc string
onParse Argument
Résultat KeywordArgument

AddPositionalArgument() public méthode

Convenience method for defining a new positional argument.
public AddPositionalArgument ( string key, string desc ) : PositionalArgument
key string
desc string
Résultat PositionalArgument

AddPositionalArgument() public méthode

Convenience method for defining a new positional argument.
public AddPositionalArgument ( string key, string desc, Argument onParse ) : PositionalArgument
key string
desc string
onParse Argument
Résultat PositionalArgument

ClassifyArguments() public méthode

Classifies the supplied list of arguments, returning a count of the number of positional arguments found.
public ClassifyArguments ( IEnumerable args ) : int
args IEnumerable
Résultat int

ClearArguments() public méthode

Clear existing arguments from the definition.
public ClearArguments ( ) : void
Résultat void

ClearLine() public méthode

Clears the last text written to the console using Write. Note that this may be more than a single line of text, if the window width is less than the length of the string written.
public ClearLine ( ) : void
Résultat void

DisplayTitle() public méthode

Displays the application title, version etc.
public DisplayTitle ( TextWriter console ) : void
console System.IO.TextWriter
Résultat void

DisplayUsage() public méthode

Displays a usgae message, based on the allowed arguments and purpose represented by this class.
public DisplayUsage ( TextWriter console, object>.Dictionary args ) : void
console System.IO.TextWriter
args object>.Dictionary
Résultat void

OutputArg() protected méthode

protected OutputArg ( Argument arg, TextWriter console ) : void
arg Argument
console System.IO.TextWriter
Résultat void

Parse() public méthode

Parses the supplied set of arg strings using the list of Argument definitions maintained by this command-line UI instance.
public Parse ( IEnumerable args ) : object>.Dictionary
args IEnumerable
Résultat object>.Dictionary

ReadLine() public méthode

For completeness - read a line of input from the console.
public ReadLine ( string prompt ) : string
prompt string
Résultat string

ReadPassword() public méthode

Reads a password from the command-line, echoing * for each keypress.
public ReadPassword ( string prompt ) : string
prompt string
Résultat string

RegisterCtrlHandler() public static méthode

This method registers this class as a handler for Ctrl-C etc events in the console. It returns a handle to the handler, which should be referenced via the following at the end of the program Main method: GC.KeepAlive(hr);
public static RegisterCtrlHandler ( ) : Win32.Handler
Résultat Win32.Handler

UI() public méthode

Constructor; requires a purpose for the program whose args we are parsing.
public UI ( string help ) : System
help string
Résultat System

WithColor() public méthode

Performs the specified operation +op+ with the console color temporarily changed to +color+. On completion of the operation, the color is reset to the original color.
public WithColor ( ConsoleColor color, System.Action op ) : void
color ConsoleColor
op System.Action
Résultat void

Write() public méthode

Writes a partial line of text to the console, without moving to the next line.
public Write ( string line ) : void
line string
Résultat void

WriteLine() public méthode

Writes a blank line to the console.
public WriteLine ( ) : void
Résultat void

WriteLine() public méthode

Writes a line of text to the console, ensuring lines the same width as the console don't output an unnecessary new-line.
public WriteLine ( string text ) : void
text string
Résultat void

Property Details

Definition public_oe property

public Definition,CommandLine Definition
Résultat Definition

Interrupted public_oe static_oe property

Static public flag indicating that the application is to terminate immediately, e.g. in response to a Ctrl-C or Logoff event. Any long- running command should check this flag periodically and attempt to abort gracefully.
public static bool Interrupted
Résultat bool

IsRedirected public_oe static_oe property

public static bool IsRedirected
Résultat bool

_log protected_oe static_oe property

protected static ILog,log4net _log
Résultat log4net.ILog