console-extra icon indicating copy to clipboard operation
console-extra copied to clipboard

How to set the command help

Open tacman opened this issue 3 years ago • 4 comments

bin/console my:command --help 
bin/console make:crud --help 

Symfony's make:crud shows some help lines at the bottom, how is that set in an invokable command? I tried adding this to __invoke, but it didn't seem to work (although again, it might be related to lazy-loading).

        $this
            // the command help shown when running the command with the "--help" option
            ->setHelp('This is the help, not the description, and can be multiple lines.');

tacman avatar Oct 02 '22 11:10 tacman

Ah, I had put it in the wrong spot, it needs to be set in configure()

    public function configure(): void
    {
        $this->setHelp("This is the help for my:command");
    }

tacman avatar Oct 02 '22 11:10 tacman

What do you think about a class attribute for help, so as to avoid calling this,

#[AsCommand('my:command', 'From the extra-console documentation')]
#[CommandHelp(help: 'This is the help for my:command']
final class MyCommand extends InvokableServiceCommand

Of course, looking at this I have to wonder if this shouldn't just be added to the AsCommand attribute.

With an attribute in this class, what about having the option of passing in a filename? Symfony puts the help in separate files:

image

tacman avatar Oct 03 '22 16:10 tacman

Yeah, that could indeed be useful!

kbond avatar Oct 03 '22 16:10 kbond

What do you think about proposing for AsCommand itself in Symfony?

#[AsCommand('my:command', help: __DIR__.'/..')]

kbond avatar Dec 06 '22 14:12 kbond