|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Spike library |
|
4
|
|
|
* @author Tao <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Spike\Server\Command; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\Console\Helper\DescriptorHelper; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class SpikeCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritdoc} |
|
18
|
|
|
*/ |
|
19
|
|
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->ignoreValidationErrors(); |
|
22
|
|
|
$this->setName('spiked') |
|
23
|
|
|
->setDefinition($this->createDefinition()) |
|
24
|
|
|
->setDescription('Spike is a reverse proxy that help to expose your local server to the internet.'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
31
|
|
|
{ |
|
32
|
|
|
$helper = new DescriptorHelper(); |
|
33
|
|
|
$helper->describe($output, $this, array( |
|
34
|
|
|
'format' => $input->getOption('format'), |
|
35
|
|
|
'raw_text' => $input->getOption('raw'), |
|
36
|
|
|
)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getNativeDefinition() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->createDefinition(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
private function createDefinition() |
|
51
|
|
|
{ |
|
52
|
|
|
return new InputDefinition(array( |
|
53
|
|
|
new InputOption('config', null, InputOption::VALUE_OPTIONAL, |
|
54
|
|
|
'The configuration file, support json,ini,xml and yaml format'), |
|
55
|
|
|
new InputOption('address', null, InputOption::VALUE_OPTIONAL, |
|
56
|
|
|
'The server address'), |
|
57
|
|
|
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), |
|
58
|
|
|
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), |
|
59
|
|
|
)); |
|
60
|
|
|
} |
|
61
|
|
|
} |