|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helick\LocalServer; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\Command\BaseCommand; |
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class Command extends BaseCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Registered subcommands. |
|
15
|
|
|
* |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
private $subcommands = [ |
|
19
|
|
|
'build' => Subcommands\BuildSubcommand::class, |
|
20
|
|
|
'start' => Subcommands\StartSubcommand::class, |
|
21
|
|
|
'stop' => Subcommands\StopSubcommand::class, |
|
22
|
|
|
'destroy' => Subcommands\DestroySubcommand::class, |
|
23
|
|
|
'status' => Subcommands\StatusSubcommand::class, |
|
24
|
|
|
'logs' => Subcommands\LogsSubcommand::class, |
|
25
|
|
|
'cli' => Subcommands\CliSubcommand::class, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritDoc |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function configure() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->setName('local-server') |
|
34
|
|
|
->setDescription('Run the local server.') |
|
35
|
|
|
->setDefinition([ |
|
36
|
|
|
new InputArgument('subcommand', InputArgument::REQUIRED, 'start, stop, destroy, status, logs, cli'), |
|
37
|
|
|
new InputArgument('options', InputArgument::IS_ARRAY), |
|
38
|
|
|
]) |
|
39
|
|
|
->setHelp( |
|
40
|
|
|
<<<EOT |
|
41
|
|
|
Run the local server. |
|
42
|
|
|
|
|
43
|
|
|
Build the local server: |
|
44
|
|
|
build |
|
45
|
|
|
Start the local server: |
|
46
|
|
|
start |
|
47
|
|
|
Stop the local server: |
|
48
|
|
|
stop |
|
49
|
|
|
Destroy the local server: |
|
50
|
|
|
destroy |
|
51
|
|
|
View the local server status: |
|
52
|
|
|
status |
|
53
|
|
|
View the local server logs: |
|
54
|
|
|
logs <service> <service> can be nginx, php, mysql, elasticsearch |
|
55
|
|
|
Run WP CLI command: |
|
56
|
|
|
cli -- <command> eg: cli -- post list |
|
57
|
|
|
EOT |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritDoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function isProxyCommand() |
|
65
|
|
|
{ |
|
66
|
|
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritDoc |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
73
|
|
|
{ |
|
74
|
|
|
$subcommand = $input->getArgument('subcommand'); |
|
75
|
|
|
|
|
76
|
|
|
if (!isset($this->subcommands[$subcommand])) { |
|
77
|
|
|
throw new InvalidArgumentException('Invalid subcommand given: ' . $subcommand); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$subcommandClass = $this->subcommands[$subcommand]; |
|
81
|
|
|
$subcommandInstance = new $subcommandClass($this->getApplication()); |
|
82
|
|
|
|
|
83
|
|
|
$subcommandInstance($input, $output); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|