1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 16:40:05 +01:00

Format output using <details> + <summary> and add plain text flag to opt out

This commit is contained in:
Aryeh Raber
2020-04-25 16:29:53 +02:00
parent 5baccdbb54
commit 86fa649362
2 changed files with 28 additions and 8 deletions

View File

@@ -57,23 +57,25 @@ function __construct(CommandLine $cli, Filesystem $files)
/** /**
* Run diagnostics. * Run diagnostics.
*/ */
function run($print) function run($print, $plainText)
{ {
$this->print = $print; $this->print = $print;
$this->beforeRun(); $this->beforeRun();
$result = collect($this->commands)->map(function ($command) { $results = collect($this->commands)->map(function ($command) {
$this->beforeCommand($command); $this->beforeCommand($command);
$output = $this->cli->runAsUser($command); $output = $this->cli->runAsUser($command);
$this->afterCommand($command, $output); $this->afterCommand($command, $output);
return implode(PHP_EOL, ["$ $command", trim($output)]); return compact('command', 'output');
})->implode(PHP_EOL.str_repeat('-', 25).PHP_EOL); });
$this->files->put('valet_diagnostics.txt', $result); $output = $this->format($results, $plainText);
$this->files->put('valet_diagnostics.txt', $output);
$this->cli->run('pbcopy < valet_diagnostics.txt'); $this->cli->run('pbcopy < valet_diagnostics.txt');
@@ -117,4 +119,21 @@ function afterCommand($command, $output)
$this->progressBar->advance(); $this->progressBar->advance();
} }
} }
function format($results, $plainText)
{
return $results->map(function ($result) use ($plainText) {
$command = $result['command'];
$output = trim($result['output']);
if ($plainText) {
return implode(PHP_EOL, ["$ {$command}", $output]);
}
return sprintf(
'<details>%s<summary>%s</summary>%s<pre>%s</pre>%s</details>',
PHP_EOL, $command, PHP_EOL, $output, PHP_EOL
);
})->implode($plainText ? PHP_EOL.str_repeat('-', 20).PHP_EOL : PHP_EOL);
}
} }

View File

@@ -537,14 +537,15 @@
/** /**
* Output diagnostics to aid in debugging Valet. * Output diagnostics to aid in debugging Valet.
*/ */
$app->command('diagnose [-p|--print]', function ($print) { $app->command('diagnose [-p|--print] [--plain]', function ($print, $plain) {
info('Running diagnostics...'); info('Running diagnostics...');
Diagnose::run($print); Diagnose::run($print, $plain);
info('Diagnostics output has been copied to your clipboard.'); info('Diagnostics output has been copied to your clipboard.');
})->descriptions('Output diagnostics to aid in debugging Valet.', [ })->descriptions('Output diagnostics to aid in debugging Valet.', [
'--print' => 'print diagnostics output while running' '--print' => 'print diagnostics output while running',
'--plain' => 'format clipboard output as plain text',
]); ]);
} }