PHP Class 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.
Author: Steve Clay ([email protected])
Datei anzeigen Open project: mrclay/minify

Public Properties

Property Type Description
$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 Properties

Property Type Description
$_args MrClay\Cli\Arg[]
$_stdin resource
$_stdout resource

Public Methods

Method Description
__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

Protected Methods

Method Description
addError ( string $letter, string $msg, string $value = null )

Method Details

__construct() public method

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

addArgument() public method

public addArgument ( string $letter, boolean $required, Arg $arg = null ) : Arg
$letter string
$required boolean
$arg MrClay\Cli\Arg
return MrClay\Cli\Arg

addError() protected method

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

addOptionalArg() public method

public addOptionalArg ( Arg | string $letter ) : Arg
$letter MrClay\Cli\Arg | string
return MrClay\Cli\Arg

addRequiredArg() public method

public addRequiredArg ( Arg | string $letter ) : Arg
$letter MrClay\Cli\Arg | string
return MrClay\Cli\Arg

closeInput() public method

public closeInput ( )

closeOutput() public method

public closeOutput ( )

getArgument() public method

public getArgument ( string $letter ) : Arg | null
$letter string
return MrClay\Cli\Arg | null

getArgumentsListing() public method

public getArgumentsListing ( ) : string
return string

getErrorReport() public method

Get a short list of errors with options
public getErrorReport ( ) : string
return string

getPathArgs() public method

Get the full paths of file(s) passed in as unspecified arguments
public getPathArgs ( ) : array
return array

openInput() public method

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
return resource

openOutput() public method

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
return resource

validate() public method

* Read and validate options
public validate ( )

Property Details

$_args protected_oe property

protected Arg[],MrClay\Cli $_args
return MrClay\Cli\Arg[]

$_stdin protected_oe property

protected resource $_stdin
return resource

$_stdout protected_oe property

protected resource $_stdout
return resource

$debug public_oe property

public array $debug
return array

$errors public_oe property

validation errors
public $errors

$isHelpRequest public_oe property

The user wants help info
public $isHelpRequest

$moreArgs public_oe property

public array $moreArgs
return array

$values public_oe property

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