Completed
Push — master ( b397d8...b5ae03 )
by Sebastian
08:12
created

Help::setCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
    protected function configure()
39
    {
40
        $this->setName('help')
41
             ->setDescription('Shows this help message')
42
             ->setHelp('Shows this help message')
43
             ->setDefinition([
44
                new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help')
45
             ]);
46
    }
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([
75
                '<info>CaptainHook</info> version <comment>' . CH::VERSION . '</comment> ' . CH::RELEASE_DATE,
76
                '',
77
                '<comment>Usage:</comment>',
78
                '  captainhook [command] [options]',
79
                '',
80
                '<comment>Available commands:</comment>',
81
                '  <info>help</info>      Outputs this help message',
82
                '  <info>configure</info> Create a CaptainHook configuration',
83
                '  <info>install</info>   Install hooks to your .git/hooks directory',
84
                '',
85
                '<comment>Help:</comment>',
86
                '  Use captainhook [command] --help for further instructions.',
87
                '',
88
                '<comment>Options:</comment>',
89
                '  <info>-h, --help</info>             Display this help message',
90
                '  <info>-q, --quiet</info>            Do not output any message',
91
                '  <info>-V, --version</info>          Display this application version',
92
                '  <info>-n, --no-interaction</info>   Do not ask any interactive question',
93
                '      <info>--ansi</info>             Force ANSI output',
94
                '      <info>--no-ansi</info>          Disable ANSI output',
95
                '  <info>-v|vv|vvv, --verbose</info>   Increase the verbosity of messages',
96
                '',
97
98
        ]);
99
    }
100
}
101