HelpFormatter
in package
HelpFormatter formats help for console shells. Can format to either text or XML formats. Uses ConsoleOptionParser methods to generate help.
Generally not directly used. Using $parser->help($command, 'xml'); is usually
how you would access help. Or via the --help=xml
option on the command line.
Xml output is useful for integration with other tools like IDE's or other build tools.
Table of Contents
Properties
- $_alias : string
- Alias to display in the output.
- $_maxArgs : int
- The maximum number of arguments shown when generating usage.
- $_maxOptions : int
- The maximum number of options shown when generating usage.
- $_parser : ConsoleOptionParser
- Option parser.
Methods
- __construct() : mixed
- Build the help formatter for an OptionParser
- setAlias() : void
- Set the alias
- text() : string
- Get the help as formatted text suitable for output on the command line.
- xml() : SimpleXMLElement|string
- Get the help as an XML string.
- _generateUsage() : string
- Generate the usage for a shell based on its arguments and options.
- _getMaxLength() : int
- Iterate over a collection and find the longest named thing.
Properties
$_alias
Alias to display in the output.
protected
string
$_alias
= 'cake'
$_maxArgs
The maximum number of arguments shown when generating usage.
protected
int
$_maxArgs
= 6
$_maxOptions
The maximum number of options shown when generating usage.
protected
int
$_maxOptions
= 6
$_parser
Option parser.
protected
ConsoleOptionParser
$_parser
Methods
__construct()
Build the help formatter for an OptionParser
public
__construct(ConsoleOptionParser $parser) : mixed
Parameters
- $parser : ConsoleOptionParser
-
The option parser help is being generated for.
setAlias()
Set the alias
public
setAlias(string $alias) : void
Parameters
- $alias : string
-
The alias
text()
Get the help as formatted text suitable for output on the command line.
public
text([int $width = 72 ]) : string
Parameters
- $width : int = 72
-
The width of the help output.
Return values
stringxml()
Get the help as an XML string.
public
xml([bool $string = true ]) : SimpleXMLElement|string
Parameters
- $string : bool = true
-
Return the SimpleXml object or a string. Defaults to true.
Return values
SimpleXMLElement|string —See $string
_generateUsage()
Generate the usage for a shell based on its arguments and options.
protected
_generateUsage() : string
Usage strings favor short options over the long ones. and optional args will be indicated with []
Return values
string_getMaxLength()
Iterate over a collection and find the longest named thing.
protected
_getMaxLength(array<string|int, ConsoleInputOption|ConsoleInputArgument|ConsoleInputSubcommand> $collection) : int
Parameters
- $collection : array<string|int, ConsoleInputOption|ConsoleInputArgument|ConsoleInputSubcommand>
-
The collection to find a max length of.