|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Cubiche package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) Cubiche |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Cubiche\Core\Console\Api\Config; |
|
13
|
|
|
|
|
14
|
|
|
use Webmozart\Console\Api\Config\CommandConfig as BaseCommandConfig; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* CommandConfig class. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class CommandConfig extends BaseCommandConfig |
|
22
|
|
|
{ |
|
23
|
|
|
use CommandConfigTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Starts a configuration block for a sub-command. |
|
27
|
|
|
* |
|
28
|
|
|
* A sub-command is executed if the name of the command is passed after the |
|
29
|
|
|
* name of the containing command. For example, if the command "server" has |
|
30
|
|
|
* a sub-command command named "add", that command can be called with: |
|
31
|
|
|
* |
|
32
|
|
|
* ``` |
|
33
|
|
|
* $ console server add ... |
|
34
|
|
|
* ``` |
|
35
|
|
|
* |
|
36
|
|
|
* The configuration of the sub-command is returned by this method. You can |
|
37
|
|
|
* use the fluent interface to configure the sub-command before jumping back |
|
38
|
|
|
* to this configuration with {@link SubCommandConfig::end()}: |
|
39
|
|
|
* |
|
40
|
|
|
* ```php |
|
41
|
|
|
* protected function configure() |
|
42
|
|
|
* { |
|
43
|
|
|
* $this |
|
44
|
|
|
* ->beginCommand('server') |
|
45
|
|
|
* ->setDescription('List and manage servers') |
|
46
|
|
|
* |
|
47
|
|
|
* ->beginSubCommand('add') |
|
48
|
|
|
* ->setDescription('Add a server') |
|
49
|
|
|
* ->addArgument('host', Argument::REQUIRED) |
|
50
|
|
|
* ->addOption('port', 'p', Option::VALUE_OPTIONAL, null, 80) |
|
51
|
|
|
* ->end() |
|
52
|
|
|
* ->end() |
|
53
|
|
|
* |
|
54
|
|
|
* // ... |
|
55
|
|
|
* ; |
|
56
|
|
|
* } |
|
57
|
|
|
* ``` |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $name The name of the sub-command. |
|
60
|
|
|
* |
|
61
|
|
|
* @return SubCommandConfig The sub-command configuration. |
|
62
|
|
|
* |
|
63
|
|
|
* @see editSubCommand() |
|
64
|
|
|
*/ |
|
65
|
|
|
public function beginSubCommand($name) |
|
66
|
|
|
{ |
|
67
|
|
|
$config = new SubCommandConfig($name, $this); |
|
68
|
|
|
|
|
69
|
|
|
$this->addSubCommandConfig($config); |
|
70
|
|
|
|
|
71
|
|
|
return $config; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|