-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowInputArgs.php
60 lines (52 loc) · 1.52 KB
/
ShowInputArgs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Commands;
use Console\Io\InputInterface;
use Console\Io\OutputInterface;
/**
* Тестовая команда. Выводит все входящие параметры команды.
*/
class ShowInputArgs implements \Console\Command
{
function getName(): string
{
return 'command_name';
}
function getDescription(): string
{
return 'Shows all arguments and parameters of the current launch';
}
function execute(InputInterface $input, OutputInterface $output)
{
$args = $input->getInputArgs();
$arguments = [];
$options = [];
foreach ($args as $arg) {
if ($arg->isArgument()) {
$arguments[] = $arg;
} else {
$options[] = $arg;
}
}
$output->out("Called command: {$this->getName()}");
if ($arguments) {
$output->out();
$output->out('Arguments:');
foreach ($arguments as $argument) {
$output->out(" - {$argument->getName()}");
}
}
if ($options) {
$output->out();
$output->out('Options:');
foreach ($options as $option) {
$output->out(" - {$option->getName()}");
if (!$option->getValues()) {
continue;
}
foreach ($option->getValues() as $value) {
$output->out(" - $value");
}
}
}
}
}