C# Класс 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.
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
Definition Definition
Interrupted bool
IsRedirected bool

Защищенные свойства (Protected)

Свойство Тип Описание
_log log4net.ILog

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
OutputArg ( Argument arg, TextWriter console ) : void

Приватные методы

Метод Описание
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.

Описание методов

AddFlagArgument() публичный Метод

Convenience method for defining a new flag argument.
public AddFlagArgument ( string key, string desc ) : FlagArgument
key string
desc string
Результат FlagArgument

AddFlagArgument() публичный Метод

Convenience method for defining a new flag argument.
public AddFlagArgument ( string key, string desc, Argument onParse ) : FlagArgument
key string
desc string
onParse Argument
Результат FlagArgument

AddKeywordArgument() публичный Метод

Convenience method for defining a new keyword argument.
public AddKeywordArgument ( string key, string desc ) : KeywordArgument
key string
desc string
Результат KeywordArgument

AddKeywordArgument() публичный Метод

Convenience method for defining a new keyword argument.
public AddKeywordArgument ( string key, string desc, Argument onParse ) : KeywordArgument
key string
desc string
onParse Argument
Результат KeywordArgument

AddPositionalArgument() публичный Метод

Convenience method for defining a new positional argument.
public AddPositionalArgument ( string key, string desc ) : PositionalArgument
key string
desc string
Результат PositionalArgument

AddPositionalArgument() публичный Метод

Convenience method for defining a new positional argument.
public AddPositionalArgument ( string key, string desc, Argument onParse ) : PositionalArgument
key string
desc string
onParse Argument
Результат PositionalArgument

ClassifyArguments() публичный Метод

Classifies the supplied list of arguments, returning a count of the number of positional arguments found.
public ClassifyArguments ( IEnumerable args ) : int
args IEnumerable
Результат int

ClearArguments() публичный Метод

Clear existing arguments from the definition.
public ClearArguments ( ) : void
Результат void

ClearLine() публичный Метод

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
Результат void

DisplayTitle() публичный Метод

Displays the application title, version etc.
public DisplayTitle ( TextWriter console ) : void
console System.IO.TextWriter
Результат void

DisplayUsage() публичный Метод

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
Результат void

OutputArg() защищенный Метод

protected OutputArg ( Argument arg, TextWriter console ) : void
arg Argument
console System.IO.TextWriter
Результат void

Parse() публичный Метод

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
Результат object>.Dictionary

ReadLine() публичный Метод

For completeness - read a line of input from the console.
public ReadLine ( string prompt ) : string
prompt string
Результат string

ReadPassword() публичный Метод

Reads a password from the command-line, echoing * for each keypress.
public ReadPassword ( string prompt ) : string
prompt string
Результат string

RegisterCtrlHandler() публичный статический Метод

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
Результат Win32.Handler

UI() публичный Метод

Constructor; requires a purpose for the program whose args we are parsing.
public UI ( string help ) : System
help string
Результат System

WithColor() публичный Метод

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
Результат void

Write() публичный Метод

Writes a partial line of text to the console, without moving to the next line.
public Write ( string line ) : void
line string
Результат void

WriteLine() публичный Метод

Writes a blank line to the console.
public WriteLine ( ) : void
Результат void

WriteLine() публичный Метод

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
Результат void

Описание свойств

Definition публичное свойство

public Definition,CommandLine Definition
Результат Definition

Interrupted публичное статическое свойство

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
Результат bool

IsRedirected публичное статическое свойство

public static bool IsRedirected
Результат bool

_log защищенное статическое свойство

protected static ILog,log4net _log
Результат log4net.ILog