Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
suggestOptions example
$this
->
log
(
' No command found, completing using the Application class.'
)
;
// expand shortcut names ("cache:cl<TAB>") into their full name ("cache:clear")
$suggestions
->
suggestValues
(
array_filter
(
array_merge
(
[
$command
->
getName
(
)
]
,
$command
->
getAliases
(
)
)
)
)
;
}
else
{
$command
->
mergeApplicationDefinition
(
)
;
$completionInput
->
bind
(
$command
->
getDefinition
(
)
)
;
if
(
CompletionInput::TYPE_OPTION_NAME ===
$completionInput
->
getCompletionType
(
)
)
{
$this
->
log
(
' Completing option names for the <comment>'.
(
$command
instanceof LazyCommand ?
$command
->
getCommand
(
)
:
$command
)
::
class
.'</> command.'
)
;
$suggestions
->
suggestOptions
(
$command
->
getDefinition
(
)
->
getOptions
(
)
)
;
}
else
{
$this
->
log
(
[
' Completing using the <comment>'.
(
$command
instanceof LazyCommand ?
$command
->
getCommand
(
)
:
$command
)
::
class
.'</> class.',
' Completing <comment>'.
$completionInput
->
getCompletionType
(
)
.'</> for <comment>'.
$completionInput
->
getCompletionName
(
)
.'</>',
]
)
;
if
(
null !==
$compval
=
$completionInput
->
getCompletionValue
(
)
)
{
$this
->
log
(
' Current value: <comment>'.
$compval
.'</>'
)
;
}
$command
->
complete
(
$completionInput
,
$suggestions
)
;
}
}
$suggestions
->
suggestValue
(
new
Suggestion
(
$command
->
getName
(
)
,
$command
->
getDescription
(
)
)
)
;
foreach
(
$command
->
getAliases
(
)
as
$name
)
{
$suggestions
->
suggestValue
(
new
Suggestion
(
$name
,
$command
->
getDescription
(
)
)
)
;
}
}
return
;
}
if
(
CompletionInput::TYPE_OPTION_NAME ===
$input
->
getCompletionType
(
)
)
{
$suggestions
->
suggestOptions
(
$this
->
getDefinition
(
)
->
getOptions
(
)
)
;
return
;
}
}
/** * Gets the help message. */
public
function
getHelp
(
)
: string
{
return
$this
->
getLongVersion
(
)
;
}
$suggestions
->
suggestValue
(
new
Suggestion
(
$command
->
getName
(
)
,
$command
->
getDescription
(
)
)
)
;
foreach
(
$command
->
getAliases
(
)
as
$name
)
{
$suggestions
->
suggestValue
(
new
Suggestion
(
$name
,
$command
->
getDescription
(
)
)
)
;
}
}
return
;
}
if
(
CompletionInput::TYPE_OPTION_NAME ===
$input
->
getCompletionType
(
)
)
{
$suggestions
->
suggestOptions
(
$this
->
getDefinition
(
)
->
getOptions
(
)
)
;
return
;
}
}
/** * Gets the help message. */
public
function
getHelp
(
)
: string
{
return
$this
->
getLongVersion
(
)
;
}
abstract
public
function
getExpectedOptionsOutput
(
)
: string;
abstract
public
function
getExpectedValuesOutput
(
)
: string;
public
function
testOptionsOutput
(
)
{
$options
=
[
new
InputOption
(
'option1', 'o', InputOption::VALUE_NONE, 'First Option'
)
,
new
InputOption
(
'negatable', null, InputOption::VALUE_NEGATABLE, 'Can be negative'
)
,
]
;
$suggestions
=
new
CompletionSuggestions
(
)
;
$suggestions
->
suggestOptions
(
$options
)
;
$stream
=
fopen
(
'php://memory', 'rw+'
)
;
$this
->
getCompletionOutput
(
)
->
write
(
$suggestions
,
new
StreamOutput
(
$stream
)
)
;
fseek
(
$stream
, 0
)
;
$this
->
assertEquals
(
$this
->
getExpectedOptionsOutput
(
)
,
stream_get_contents
(
$stream
)
)
;
}
public
function
testValuesOutput
(
)
{
$suggestions
=
new
CompletionSuggestions
(
)
;
$suggestions
->
suggestValues
(
[
new
Suggestion
(
'Green', 'Beans are green'
)
,
$this
->
log
(
' No command found, completing using the Application class.'
)
;
// expand shortcut names ("cache:cl<TAB>") into their full name ("cache:clear")
$suggestions
->
suggestValues
(
array_filter
(
array_merge
(
[
$command
->
getName
(
)
]
,
$command
->
getAliases
(
)
)
)
)
;
}
else
{
$command
->
mergeApplicationDefinition
(
)
;
$completionInput
->
bind
(
$command
->
getDefinition
(
)
)
;
if
(
CompletionInput::TYPE_OPTION_NAME ===
$completionInput
->
getCompletionType
(
)
)
{
$this
->
log
(
' Completing option names for the <comment>'.
(
$command
instanceof LazyCommand ?
$command
->
getCommand
(
)
:
$command
)
::
class
.'</> command.'
)
;
$suggestions
->
suggestOptions
(
$command
->
getDefinition
(
)
->
getOptions
(
)
)
;
}
else
{
$this
->
log
(
[
' Completing using the <comment>'.
(
$command
instanceof LazyCommand ?
$command
->
getCommand
(
)
:
$command
)
::
class
.'</> class.',
' Completing <comment>'.
$completionInput
->
getCompletionType
(
)
.'</> for <comment>'.
$completionInput
->
getCompletionName
(
)
.'</>',
]
)
;
if
(
null !==
$compval
=
$completionInput
->
getCompletionValue
(
)
)
{
$this
->
log
(
' Current value: <comment>'.
$compval
.'</>'
)
;
}
$command
->
complete
(
$completionInput
,
$suggestions
)
;
}
}