From 8e7d8dc74eb31cfc3b5518f64f6eac274b442a9e 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 | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Steps/Step.php b/src/Steps/Step.php index 8c27d88..c61606d 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 && $verbosity === OutputInterface::VERBOSITY_DEBUG) { + $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..38ff40f 100644 --- a/src/Utility/StepCommandRunner.php +++ b/src/Utility/StepCommandRunner.php @@ -28,10 +28,11 @@ 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); }