zenstruck / console-extra

A modular set of features to reduce configuration boilerplate for your Symfony commands.
MIT License
78 stars 3 forks source link

export command as string that can be run on the command line #51

Closed tacman closed 1 year ago

tacman commented 1 year ago

When a command fails, I'd like to dump it and run it in my own terminal, as errors are easier to see. Is there a way to expand a comand so I can see the arguments and parameters?

        $command = $this->getApplication()->find('liip:imagine:cache:resolve');

        $arguments = [
            'paths' => [$path],
            '--filter' => $filter,
            '--force' => $force,
            '-vv' => true,
        ];

        $greetInput = new ArrayInput($arguments);
        $returnCode = $command->run($greetInput, $output);
        if ($returnCode) {
             // how can I print liip:imagine:cache:resolve $paths --filter=$filter, etc. so I can cut and paste it to the command line?
            assert(false, $path . ' returned ' . $returnCode);
        }
kbond commented 1 year ago

When running command's problematically, I always use StringInput so I can access the proper string it was run with.

kbond commented 1 year ago

Looks like InputInterface has a __toString() method as of Symfony 6.1.

You should be able to use (string) $greetInput in your example above.

tacman commented 1 year ago

Yep! I missed that, thanks!