HelpCommand.php 1.09 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
<?php
namespace Consolidation\AnnotatedCommand\Help;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class HelpCommand
{
    /** var Application */
    protected $application;

    /**
     * Create a help document from a Symfony Console command
     */
    public function __construct(Application $application)
    {
        $this->application = $application;
    }

    public function getApplication()
    {
        return $this->application;
    }

    /**
     * Run the help command
     *
     * @command my-help
     * @return \Consolidation\AnnotatedCommand\Help\HelpDocument
     */
    public function help($commandName = 'help')
    {
        $command = $this->getApplication()->find($commandName);

        $helpDocument = $this->getHelpDocument($command);
        return $helpDocument;
    }

    /**
     * Create a help document.
     */
    protected function getHelpDocument($command)
    {
        return new HelpDocument($command);
    }
}