Completed
Push — master ( 92b30b...8d784e )
by Sebastian
09:22
created

Help::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\CaptainHook\Console\Command;
11
12
use SebastianFeldmann\CaptainHook\CH;
13
use Symfony\Component\Console\Command\Command as SymfonyCommand;
14
use Symfony\Component\Console\Helper\DescriptorHelper;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class Help
22
 *
23
 * @package CaptainHook
24
 * @author  Sebastian Feldmann <[email protected]>
25
 * @link    https://github.com/sebastianfeldmann/captainhook
26
 * @since   Class available since Release 2.0.6
27
 */
28
class Help extends Base
29
{
30
    /**
31
     * @var \Symfony\Component\Console\Command\Command
32
     */
33
    private $command;
34
35
    /**
36
     * Configure the command.
37
     */
38 1
    protected function configure()
39
    {
40 1
        $this->setName('help')
41 1
             ->setDescription('Shows this help message')
42 1
             ->setHelp('Shows this help message')
43 1
             ->setDefinition([
44 1
                new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help')
45
             ]);
46 1
    }
47
48
    /**
49
     * Set command to get help for.
50
     *
51
     * @param \Symfony\Component\Console\Command\Command $command
52
     */
53
    public function setCommand(SymfonyCommand $command)
54
    {
55
        $this->command = $command;
56
    }
57
58
    /**
59
     * Execute the command.
60
     *
61
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
62
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
63
     * @return void
64
     */
65
    protected function execute(InputInterface $input, OutputInterface $output)
66
    {
67
        if ($this->command) {
68
            $helper = new DescriptorHelper();
69
            $helper->describe($output, $this->command);
70
            return;
71
        }
72
73
        $io = $this->getIO($input, $output);
74
        $io->write(array_merge(
75
            $this->getVersion(),
76
            $this->getCommandList(),
77
            $this->getOptions()
78
        ));
79
    }
80
81
    /**
82
     * Return help rows for version and basic usage.
83
     *
84
     * @return array
85
     */
86
    private function getVersion() : array
87
    {
88
        return [
89
            $this->getApplication()->getLongVersion(),
90
            '',
91
            '<comment>Usage:</comment>',
92
            '  captainhook [command] [options]',
93
            ''
94
        ];
95
    }
96
97
    /**
98
     * Return help rows listing all commands.
99
     *
100
     * @return array
101
     */
102
    private function getCommandList() : array
103
    {
104
        return [
105
            '<comment>Available commands:</comment>',
106
            '  <info>help</info>      Outputs this help message',
107
            '  <info>configure</info> Create a CaptainHook configuration',
108
            '  <info>install</info>   Install hooks to your .git/hooks directory',
109
            ''
110
        ];
111
    }
112
113
    /**
114
     * Return help rows describing all options.
115
     *
116
     * @return array
117
     */
118
    private function getOptions() : array
119
    {
120
        return [
121
            '<comment>Options:</comment>',
122
            '  <info>-h, --help</info>             Display this help message',
123
            '  <info>-q, --quiet</info>            Do not output any message',
124
            '  <info>-V, --version</info>          Display this application version',
125
            '  <info>-n, --no-interaction</info>   Do not ask any interactive question',
126
            '      <info>--ansi</info>             Force ANSI output',
127
            '      <info>--no-ansi</info>          Disable ANSI output',
128
            '  <info>-v|vv|vvv, --verbose</info>   Increase the verbosity of messages',
129
            ''
130
        ];
131
    }
132
}
133