Class HelpFormatter

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.

Namespace: Cake\Console
Location: Console/HelpFormatter.php

Properties summary

Method Summary

  • __construct() public
    Build the help formatter for an OptionParser
  • _generateUsage() protected

    Generate the usage for a shell based on its arguments and options. Usage strings favor short options over the long ones. and optional args will be indicated with []

  • _getMaxLength() protected
    Iterate over a collection and find the longest named thing.
  • setAlias() public
    Set the alias
  • text() public
    Get the help as formatted text suitable for output on the command line.
  • xml() public
    Get the help as an xml string.

Method Detail

__construct()source public

__construct( Cake\Console\ConsoleOptionParser $parser )

Build the help formatter for an OptionParser

Parameters

Cake\Console\ConsoleOptionParser $parser
The option parser help is being generated for.

_generateUsage()source protected

_generateUsage( )

Generate the usage for a shell based on its arguments and options. Usage strings favor short options over the long ones. and optional args will be indicated with []

Returns

string

_getMaxLength()source protected

_getMaxLength( array $collection )

Iterate over a collection and find the longest named thing.

Parameters

array $collection
The collection to find a max length of.

Returns

integer

setAlias()source public

setAlias( string $alias )

Set the alias

Parameters

string $alias
The alias

Throws

Cake\Console\Exception\ConsoleException
When alias is not a string.

text()source public

text( integer $width = 72 )

Get the help as formatted text suitable for output on the command line.

Parameters

integer $width optional 72
The width of the help output.

Returns

string

xml()source public

xml( boolean $string = true )

Get the help as an xml string.

Parameters

boolean $string optional true
Return the SimpleXml object or a string. Defaults to true.

Returns

string|SimpleXMLElement
See $string

Properties detail

$_aliassource

protected string

Alias to display in the output.

'cake'

$_maxArgssource

protected integer

The maximum number of arguments shown when generating usage.

6

$_maxOptionssource

protected integer

The maximum number of options shown when generating usage.

6

$_parsersource

protected Cake\Console\ConsoleOptionParser

Option parser.

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.8/class-Cake.Console.HelpFormatter.html