From df24eb848f63f775f48ccbc01e038a9560f146bf Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 13 Jul 2023 15:57:09 +1200 Subject: [PATCH] ENH Do not output github token to console when -vvv is set --- src/Steps/Step.php | 16 ++++++++++++++-- src/Utility/CommandRunner.php | 3 ++- src/Utility/Composer.php | 2 +- src/Utility/StepCommandRunner.php | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Steps/Step.php b/src/Steps/Step.php index 8c27d88..e3adcd0 100644 --- a/src/Steps/Step.php +++ b/src/Steps/Step.php @@ -93,11 +93,17 @@ protected function getQuestionHelper() * or a command to run * @param string|null $error An error message that must be displayed if something went wrong * @param bool $exceptionOnError If an error occurs, this message is an exception rather than a notice + * @param bool $allowDebugVerbosity If false temporarily change -vvv to -vv so command results are not echoed * @return bool|string Output, or false if error * @throws Exception */ - public function runCommand(OutputInterface $output, $command, $error = null, $exceptionOnError = true) - { + public function runCommand( + OutputInterface $output, + $command, + $error = null, + $exceptionOnError = true, + $allowDebugVerbosity = true + ) { $helper = $this->getProcessHelper(); // Prepare unbound command @@ -114,7 +120,13 @@ public function runCommand(OutputInterface $output, $command, $error = null, $ex // Run it $process->setTimeout(null); + + $verbosity = $output->getVerbosity(); + if (!$allowDebugVerbosity && $output->isDebug()) { + $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); + } $result = $helper->run($output, $process, $error); + $output->setVerbosity($verbosity); // And cleanup if ($result->isSuccessful()) { diff --git a/src/Utility/CommandRunner.php b/src/Utility/CommandRunner.php index 0933389..e8170da 100644 --- a/src/Utility/CommandRunner.php +++ b/src/Utility/CommandRunner.php @@ -17,10 +17,11 @@ interface CommandRunner * or a command to run * @param string|null $error An error message that must be displayed if something went wrong * @param bool $exceptionOnError If an error occurs, this message is an exception rather than a notice + * @param bool $allowDebugVerbosity If false temporarily change -vvv to -vv so command results are not echoed * @return bool|string Output, or false if error * @throw Exception */ - public function runCommand($command, $error = null, $exceptionOnError = true); + public function runCommand($command, $error = null, $exceptionOnError = true, $allowDebugVerbosity = true); /* * Log a message with an optional format wrapper diff --git a/src/Utility/Composer.php b/src/Utility/Composer.php index 3801751..928a1f7 100644 --- a/src/Utility/Composer.php +++ b/src/Utility/Composer.php @@ -121,7 +121,7 @@ public static function getOAUTHToken(CommandRunner $runner) // try composer stored oauth token $command = ['composer', 'config', '-g', 'github-oauth.github.com']; $error = "Couldn't determine GitHub oAuth token. Please set GITHUB_API_TOKEN"; - $result = $runner->runCommand($command, $error); + $result = $runner->runCommand($command, $error, true, false); return trim($result); } diff --git a/src/Utility/StepCommandRunner.php b/src/Utility/StepCommandRunner.php index edbb35d..2ce8b81 100644 --- a/src/Utility/StepCommandRunner.php +++ b/src/Utility/StepCommandRunner.php @@ -28,12 +28,13 @@ public function __construct(Step $step, OutputInterface $output) * or a command to run * @param string|null $error An error message that must be displayed if something went wrong * @param bool $exceptionOnError If an error occurs, this message is an exception rather than a notice + * @param bool $allowDebugVerbosity If false temporarily change -vvv to -vv so command results are not echoed * @return bool|string Output, or false if error * @throws Exception */ - public function runCommand($command, $error = null, $exceptionOnError = true) + public function runCommand($command, $error = null, $exceptionOnError = true, $allowDebugVerbosity = true) { - return $this->step->runCommand($this->output, $command, $error, $exceptionOnError); + return $this->step->runCommand($this->output, $command, $error, $exceptionOnError, $allowDebugVerbosity); } /*