8000 [Console] Command dependencies · Issue #12495 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Command dependencies #12495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kix opened this issue Nov 17, 2014 · 3 comments
Closed

[Console] Command dependencies #12495

kix opened this issue Nov 17, 2014 · 3 comments

Comments

@kix
Copy link
Contributor
kix commented Nov 17, 2014

Currently, a Symfony command can only implement a single action supplied in its execute() method, though sometimes it's quite useful to call multiple commands sequentially (for example, if we were deploying a Symfony application on a remote host, we'd need to do a bunch of actions).

I suggest to somehow allow commands to call other commands or have a single command /depend/ on others. Here's how it could look.

First option: we could allow specifying commands to call in the configure method:

class SomeCompositeCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('my:composite:command')
            ->setDescription('Runs a bunch of other commands')
            ->setCalledCommands(array(
                'doctrine:schema:validate',
                'doctrine:schema:create',
                'cache:clear'
            ))
        ;
    }
} 

Second option: we could provide a method to call other commands inside the execute method:

class SomeCompositeCommand extends ContainerAwareCommand
{
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->invokeCommand('doctrine:schema:validate');
        $output->writeln('Validated schema');

        $this->invokeCommand('doctrine:schema:create');
    }
} 

Both these options would be pretty hard to implement, though I personally think that the second one is better. Also, some questions arise, like, how do we provide arguments to the commands we call (but having an invokeCommand method suggests an easy API here).

@malarzm
Copy link
Contributor
malarzm commented Nov 17, 2014

Invoking other command is not hard right now :)

$cmd = $this->getApplication()->find('some:command');
$cmd->run(new ArrayInput(array(/* ... */)), $output);

@kix
Copy link
Contributor Author
kix commented Nov 17, 2014

@malarzm Ouch, couldn't find that in the docs. Thanks. Closing this now :)

@kix kix closed this as completed Nov 17, 2014
@stof
Copy link
Member
stof commented Nov 17, 2014

note however that all these commands will run in the same process, and some command will not play well with this (for instance clearing or warming up the cache, as they change some class definitions, so running something after them is likely to break)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0