diff --git a/src/Composer/Command/GlobalCommand.php b/src/Composer/Command/GlobalCommand.php
index d74bf2b14..a99898e28 100644
--- a/src/Composer/Command/GlobalCommand.php
+++ b/src/Composer/Command/GlobalCommand.php
@@ -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('Changed current directory to '.$home.'');
+ if (!$quiet) {
+ $this->getIO()->writeError('Changed current directory to '.$home.'');
+ }
// 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;
}
/**