Skip to content

Commit

Permalink
ENH Do not output github token to console when -vvv is set
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 17, 2023
1 parent d87063a commit df24eb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/Steps/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Utility/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Utility/StepCommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down

0 comments on commit df24eb8

Please sign in to comment.