PHP Класс MrClay\Cli

Instantiate, add arguments, then call validate(). Afterwards, the user's valid arguments and their values will be available in $cli->values. You may also specify that some arguments be used to provide input/output. By communicating solely through the file pointers provided by openInput()/openOutput(), you can make your app more flexible to end users.
Автор: Steve Clay ([email protected])
Показать файл Открыть проект

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

Свойство Тип Описание
$debug array
$errors validation errors
$isHelpRequest The user wants help info
$moreArgs array
$values option values available after validation. E.g. array( 'a' => false // option was missing ,'b' => true // option was present ,'c' => "Hello" // option had value ,'f' => "/home/user/file" // file path from root ,'f.raw' => "~/file" // file path as given to option )

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

Свойство Тип Описание
$_args MrClay\Cli\Arg[]
$_stdin resource
$_stdout resource

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

Метод Описание
__construct ( boolean $exitIfNoStdin = true )
addArgument ( string $letter, boolean $required, Arg $arg = null ) : Arg
addOptionalArg ( Arg | string $letter ) : Arg
addRequiredArg ( Arg | string $letter ) : Arg
closeInput ( )
closeOutput ( )
getArgument ( string $letter ) : Arg | null
getArgumentsListing ( ) : string
getErrorReport ( ) : string Get a short list of errors with options
getPathArgs ( ) : array Get the full paths of file(s) passed in as unspecified arguments
openInput ( ) : resource Get resource of open input stream. May be STDIN or a file pointer to the file specified by an option with 'STDIN'.
openOutput ( ) : resource Get resource of open output stream. May be STDOUT or a file pointer to the file specified by an option with 'STDOUT'. The file will be truncated to 0 bytes on opening.
validate ( ) * Read and validate options

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

Метод Описание
addError ( string $letter, string $msg, string $value = null )

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

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

public __construct ( boolean $exitIfNoStdin = true )
$exitIfNoStdin boolean (default true) Exit() if STDIN is not defined

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

public addArgument ( string $letter, boolean $required, Arg $arg = null ) : Arg
$letter string
$required boolean
$arg MrClay\Cli\Arg
Результат MrClay\Cli\Arg

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

protected addError ( string $letter, string $msg, string $value = null )
$letter string
$msg string
$value string

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

public addOptionalArg ( Arg | string $letter ) : Arg
$letter MrClay\Cli\Arg | string
Результат MrClay\Cli\Arg

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

public addRequiredArg ( Arg | string $letter ) : Arg
$letter MrClay\Cli\Arg | string
Результат MrClay\Cli\Arg

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

public closeInput ( )

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

public closeOutput ( )

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

public getArgument ( string $letter ) : Arg | null
$letter string
Результат MrClay\Cli\Arg | null

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

public getArgumentsListing ( ) : string
Результат string

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

Get a short list of errors with options
public getErrorReport ( ) : string
Результат string

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

Get the full paths of file(s) passed in as unspecified arguments
public getPathArgs ( ) : array
Результат array

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

Get resource of open input stream. May be STDIN or a file pointer to the file specified by an option with 'STDIN'.
public openInput ( ) : resource
Результат resource

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

Get resource of open output stream. May be STDOUT or a file pointer to the file specified by an option with 'STDOUT'. The file will be truncated to 0 bytes on opening.
public openOutput ( ) : resource
Результат resource

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

* Read and validate options
public validate ( )

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

$_args защищенное свойство

protected Arg[],MrClay\Cli $_args
Результат MrClay\Cli\Arg[]

$_stdin защищенное свойство

protected resource $_stdin
Результат resource

$_stdout защищенное свойство

protected resource $_stdout
Результат resource

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

public array $debug
Результат array

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

validation errors
public $errors

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

The user wants help info
public $isHelpRequest

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

public array $moreArgs
Результат array

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

option values available after validation. E.g. array( 'a' => false // option was missing ,'b' => true // option was present ,'c' => "Hello" // option had value ,'f' => "/home/user/file" // file path from root ,'f.raw' => "~/file" // file path as given to option )
public $values