Try and add completion for global subcommands
parent
ce45d15bb5
commit
1162629a17
|
@ -37,6 +37,14 @@ class GlobalCommand extends BaseCommand
|
|||
return $command->isHidden() ? null : $command->getName();
|
||||
}, $application->all())));
|
||||
}
|
||||
|
||||
if ($application->has($commandName = $input->getArgument('command-name'))) {
|
||||
$input = $this->prepareSubcommandInput($input, true);
|
||||
$input = CompletionInput::fromString($input->__toString(), 3);
|
||||
$command = $this->getApplication()->find($commandName);
|
||||
$input->bind($command->getDefinition());
|
||||
$command->complete($input, $suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,6 +108,13 @@ EOT
|
|||
return parent::run($input, $output);
|
||||
}
|
||||
|
||||
$input = $this->prepareSubcommandInput($input);
|
||||
|
||||
return $this->getApplication()->run($input, $output);
|
||||
}
|
||||
|
||||
private function prepareSubcommandInput(InputInterface $input, bool $quiet = false): StringInput
|
||||
{
|
||||
// The COMPOSER env var should not apply to the global execution scope
|
||||
if (Platform::getEnv('COMPOSER')) {
|
||||
Platform::clearEnv('COMPOSER');
|
||||
|
@ -122,13 +137,15 @@ EOT
|
|||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Could not switch to home directory "'.$home.'"', 0, $e);
|
||||
}
|
||||
$this->getIO()->writeError('<info>Changed current directory to '.$home.'</info>');
|
||||
if (!$quiet) {
|
||||
$this->getIO()->writeError('<info>Changed current directory to '.$home.'</info>');
|
||||
}
|
||||
|
||||
// create new input without "global" command prefix
|
||||
$input = new StringInput(Preg::replace('{\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\b}', '', $input->__toString(), 1));
|
||||
$this->getApplication()->resetComposer();
|
||||
|
||||
return $this->getApplication()->run($input, $output);
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue