Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getUsages example
return
;
}
$command
->
mergeApplicationDefinition
(
false
)
;
$this
->
write
(
'`'.
$command
->
getName
(
)
."`\n"
.
str_repeat
(
'-', Helper::
width
(
$command
->
getName
(
)
)
+ 2
)
."\n\n"
.
(
$command
->
getDescription
(
)
?
$command
->
getDescription
(
)
."\n\n" : ''
)
.'### Usage'."\n\n"
.
array_reduce
(
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
,
fn
(
$carry
,
$usage
)
=>
$carry
.'* `'.
$usage
.'`'."\n"
)
)
;
if
(
$help
=
$command
->
getProcessedHelp
(
)
)
{
$this
->
write
(
"\n"
)
;
$this
->
write
(
$help
)
;
}
$definition
=
$command
->
getDefinition
(
)
;
if
(
$definition
->
getOptions
(
)
||
$definition
->
getArguments
(
)
)
{
$this
->
write
(
"\n\n"
)
;
$this
->
describeInputDefinition
(
$definition
)
;
}
$command
->
mergeApplicationDefinition
(
false
)
;
foreach
(
$command
->
getAliases
(
)
as
$alias
)
{
$this
->
write
(
'.. _'.
$alias
.":\n\n"
)
;
}
$this
->
write
(
$command
->
getName
(
)
."\n"
.
str_repeat
(
$this
->subsectionChar, Helper::
width
(
$command
->
getName
(
)
)
)
."\n\n"
.
(
$command
->
getDescription
(
)
?
$command
->
getDescription
(
)
."\n\n" : ''
)
."Usage\n".
str_repeat
(
$this
->subsubsectionChar, 5
)
."\n\n"
.
array_reduce
(
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
,
static
fn
(
$carry
,
$usage
)
=>
$carry
.'- ``'.
$usage
.'``'."\n"
)
)
;
if
(
$help
=
$command
->
getProcessedHelp
(
)
)
{
$this
->
write
(
"\n"
)
;
$this
->
write
(
$help
)
;
}
$definition
=
$command
->
getDefinition
(
)
;
if
(
$definition
->
getOptions
(
)
||
$definition
->
getArguments
(
)
)
{
$this
->
write
(
"\n\n"
)
;
$this
->
describeInputDefinition
(
$definition
)
;
}
'description' =>
$command
->
getDescription
(
)
,
]
;
if
(
$short
)
{
$data
+=
[
'usage' =>
$command
->
getAliases
(
)
,
]
;
}
else
{
$command
->
mergeApplicationDefinition
(
false
)
;
$data
+=
[
'usage' =>
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getUsages
(
)
,
$command
->
getAliases
(
)
)
,
'help' =>
$command
->
getProcessedHelp
(
)
,
'definition' =>
$this
->
getInputDefinitionData
(
$command
->
getDefinition
(
)
)
,
]
;
}
$data
[
'hidden'
]
=
$command
->
isHidden
(
)
;
return
$data
;
}
}
$command
->
addOption
(
'foo'
)
;
$command
->
addArgument
(
'bar'
)
;
$command
->
addArgument
(
'info'
)
;
$this
->
assertEquals
(
'namespace:name [--foo] [--] [<bar> [<info>]]',
$command
->
getSynopsis
(
)
, '->getSynopsis() returns the synopsis'
)
;
}
public
function
testAddGetUsages
(
)
{
$command
=
new
\
TestCommand
(
)
;
$command
->
addUsage
(
'foo1'
)
;
$command
->
addUsage
(
'foo2'
)
;
$this
->
assertContains
(
'namespace:name foo1',
$command
->
getUsages
(
)
)
;
$this
->
assertContains
(
'namespace:name foo2',
$command
->
getUsages
(
)
)
;
}
public
function
testGetHelper
(
)
{
$application
=
new
Application
(
)
;
$command
=
new
\
TestCommand
(
)
;
$command
->
setApplication
(
$application
)
;
$formatterHelper
=
new
FormatterHelper
(
)
;
$this
->
assertEquals
(
$formatterHelper
->
getName
(
)
,
$command
->
getHelper
(
'formatter'
)
->
getName
(
)
, '->getHelper() returns the correct helper'
)
;
}
'description' =>
$command
->
getDescription
(
)
,
]
;
if
(
$short
)
{
$data
+=
[
'usage' =>
$command
->
getAliases
(
)
,
]
;
}
else
{
$command
->
mergeApplicationDefinition
(
false
)
;
$data
+=
[
'usage' =>
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getUsages
(
)
,
$command
->
getAliases
(
)
)
,
'help' =>
$command
->
getProcessedHelp
(
)
,
'definition' =>
$this
->
getInputDefinitionData
(
$command
->
getDefinition
(
)
)
,
]
;
}
$data
[
'hidden'
]
=
$command
->
isHidden
(
)
;
return
$data
;
}
}
$commandXML
->
appendChild
(
$descriptionXML
=
$dom
->
createElement
(
'description'
)
)
;
$descriptionXML
->
appendChild
(
$dom
->
createTextNode
(
str_replace
(
"\n", "\n ",
$command
->
getDescription
(
)
)
)
)
;
if
(
$short
)
{
foreach
(
$command
->
getAliases
(
)
as
$usage
)
{
$usagesXML
->
appendChild
(
$dom
->
createElement
(
'usage',
$usage
)
)
;
}
}
else
{
$command
->
mergeApplicationDefinition
(
false
)
;
foreach
(
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
as
$usage
)
{
$usagesXML
->
appendChild
(
$dom
->
createElement
(
'usage',
$usage
)
)
;
}
$commandXML
->
appendChild
(
$helpXML
=
$dom
->
createElement
(
'help'
)
)
;
$helpXML
->
appendChild
(
$dom
->
createTextNode
(
str_replace
(
"\n", "\n ",
$command
->
getProcessedHelp
(
)
)
)
)
;
$definitionXML
=
$this
->
getInputDefinitionDocument
(
$command
->
getDefinition
(
)
)
;
$this
->
appendDocument
(
$commandXML
,
$definitionXML
->
getElementsByTagName
(
'definition'
)
->
item
(
0
)
)
;
}
return
$dom
;
}
return
;
}
$command
->
mergeApplicationDefinition
(
false
)
;
$this
->
write
(
'`'.
$command
->
getName
(
)
."`\n"
.
str_repeat
(
'-', Helper::
width
(
$command
->
getName
(
)
)
+ 2
)
."\n\n"
.
(
$command
->
getDescription
(
)
?
$command
->
getDescription
(
)
."\n\n" : ''
)
.'### Usage'."\n\n"
.
array_reduce
(
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
,
fn
(
$carry
,
$usage
)
=>
$carry
.'* `'.
$usage
.'`'."\n"
)
)
;
if
(
$help
=
$command
->
getProcessedHelp
(
)
)
{
$this
->
write
(
"\n"
)
;
$this
->
write
(
$help
)
;
}
$definition
=
$command
->
getDefinition
(
)
;
if
(
$definition
->
getOptions
(
)
||
$definition
->
getArguments
(
)
)
{
$this
->
write
(
"\n\n"
)
;
$this
->
describeInputDefinition
(
$definition
)
;
}
$command
->
mergeApplicationDefinition
(
false
)
;
if
(
$description
=
$command
->
getDescription
(
)
)
{
$this
->
writeText
(
'<comment>Description:</comment>',
$options
)
;
$this
->
writeText
(
"\n"
)
;
$this
->
writeText
(
' '.
$description
)
;
$this
->
writeText
(
"\n\n"
)
;
}
$this
->
writeText
(
'<comment>Usage:</comment>',
$options
)
;
foreach
(
array_merge
(
[
$command
->
getSynopsis
(
true
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
as
$usage
)
{
$this
->
writeText
(
"\n"
)
;
$this
->
writeText
(
' '.OutputFormatter::
escape
(
$usage
)
,
$options
)
;
}
$this
->
writeText
(
"\n"
)
;
$definition
=
$command
->
getDefinition
(
)
;
if
(
$definition
->
getOptions
(
)
||
$definition
->
getArguments
(
)
)
{
$this
->
writeText
(
"\n"
)
;
$this
->
describeInputDefinition
(
$definition
,
$options
)
;
$this
->
writeText
(
"\n"
)
;
}
$command
->
mergeApplicationDefinition
(
false
)
;
if
(
$description
=
$command
->
getDescription
(
)
)
{
$this
->
writeText
(
'<comment>Description:</comment>',
$options
)
;
$this
->
writeText
(
"\n"
)
;
$this
->
writeText
(
' '.
$description
)
;
$this
->
writeText
(
"\n\n"
)
;
}
$this
->
writeText
(
'<comment>Usage:</comment>',
$options
)
;
foreach
(
array_merge
(
[
$command
->
getSynopsis
(
true
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
as
$usage
)
{
$this
->
writeText
(
"\n"
)
;
$this
->
writeText
(
' '.OutputFormatter::
escape
(
$usage
)
,
$options
)
;
}
$this
->
writeText
(
"\n"
)
;
$definition
=
$command
->
getDefinition
(
)
;
if
(
$definition
->
getOptions
(
)
||
$definition
->
getArguments
(
)
)
{
$this
->
writeText
(
"\n"
)
;
$this
->
describeInputDefinition
(
$definition
,
$options
)
;
$this
->
writeText
(
"\n"
)
;
}
$commandXML
->
appendChild
(
$descriptionXML
=
$dom
->
createElement
(
'description'
)
)
;
$descriptionXML
->
appendChild
(
$dom
->
createTextNode
(
str_replace
(
"\n", "\n ",
$command
->
getDescription
(
)
)
)
)
;
if
(
$short
)
{
foreach
(
$command
->
getAliases
(
)
as
$usage
)
{
$usagesXML
->
appendChild
(
$dom
->
createElement
(
'usage',
$usage
)
)
;
}
}
else
{
$command
->
mergeApplicationDefinition
(
false
)
;
foreach
(
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
as
$usage
)
{
$usagesXML
->
appendChild
(
$dom
->
createElement
(
'usage',
$usage
)
)
;
}
$commandXML
->
appendChild
(
$helpXML
=
$dom
->
createElement
(
'help'
)
)
;
$helpXML
->
appendChild
(
$dom
->
createTextNode
(
str_replace
(
"\n", "\n ",
$command
->
getProcessedHelp
(
)
)
)
)
;
$definitionXML
=
$this
->
getInputDefinitionDocument
(
$command
->
getDefinition
(
)
)
;
$this
->
appendDocument
(
$commandXML
,
$definitionXML
->
getElementsByTagName
(
'definition'
)
->
item
(
0
)
)
;
}
return
$dom
;
}
public
function
addUsage
(
string
$usage
)
:
static
{
$this
->
getCommand
(
)
->
addUsage
(
$usage
)
;
return
$this
;
}
public
function
getUsages
(
)
: array
{
return
$this
->
getCommand
(
)
->
getUsages
(
)
;
}
public
function
getHelper
(
string
$name
)
: HelperInterface
{
return
$this
->
getCommand
(
)
->
getHelper
(
$name
)
;
}
public
function
getCommand
(
)
: parent
{
if
(
!
$this
->command instanceof \Closure
)
{
return
$this
->command;
}
public
function
addUsage
(
string
$usage
)
:
static
{
$this
->
getCommand
(
)
->
addUsage
(
$usage
)
;
return
$this
;
}
public
function
getUsages
(
)
: array
{
return
$this
->
getCommand
(
)
->
getUsages
(
)
;
}
public
function
getHelper
(
string
$name
)
: HelperInterface
{
return
$this
->
getCommand
(
)
->
getHelper
(
$name
)
;
}
public
function
getCommand
(
)
: parent
{
if
(
!
$this
->command instanceof \Closure
)
{
return
$this
->command;
}
$command
->
mergeApplicationDefinition
(
false
)
;
foreach
(
$command
->
getAliases
(
)
as
$alias
)
{
$this
->
write
(
'.. _'.
$alias
.":\n\n"
)
;
}
$this
->
write
(
$command
->
getName
(
)
."\n"
.
str_repeat
(
$this
->subsectionChar, Helper::
width
(
$command
->
getName
(
)
)
)
."\n\n"
.
(
$command
->
getDescription
(
)
?
$command
->
getDescription
(
)
."\n\n" : ''
)
."Usage\n".
str_repeat
(
$this
->subsubsectionChar, 5
)
."\n\n"
.
array_reduce
(
array_merge
(
[
$command
->
getSynopsis
(
)
]
,
$command
->
getAliases
(
)
,
$command
->
getUsages
(
)
)
,
static
fn
(
$carry
,
$usage
)
=>
$carry
.'- ``'.
$usage
.'``'."\n"
)
)
;
if
(
$help
=
$command
->
getProcessedHelp
(
)
)
{
$this
->
write
(
"\n"
)
;
$this
->
write
(
$help
)
;
}
$definition
=
$command
->
getDefinition
(
)
;
if
(
$definition
->
getOptions
(
)
||
$definition
->
getArguments
(
)
)
{
$this
->
write
(
"\n\n"
)
;
$this
->
describeInputDefinition
(
$definition
)
;
}