Console Subcommands


#1

Hi,

In the Command documentation, there is a chapter about subcommands.

$parser->addSubcommand('model', [
    'help' => 'Bake a model',
    'parser' => $this->Model->getOptionParser()
]);

The fact is, there is NO WAY to known, in the Command php script, which subcommand was called.

I’m debuging the framework code and the information of subcommand name, disappear in Cake method.
Here is the pipeline.

cake.php call CommandRunner::run with $argv (from CLI)

CommandRunner::run() call the command::run with same $argv

 if ($shell instanceof Command) {
     $result = $shell->run($argv, $io);
 }

The Command::run() call ConsoleOptionParser with untouched version of $argv, my syubcommand is still in $argv[0].

ConsoleOptionParser::parse() check if $argv[0] is a defined subcommand and … unset it and NEVER store.

The Command::run() continue, my subcommands disappear and i have no way to known which subcommand was called :frowning:

Any any on how to use Subcommands in new Command system (Shells was better i think :/)

Thanks