mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
Format output using <details> + <summary> and add plain text flag to opt out
This commit is contained in:
@@ -57,23 +57,25 @@ function __construct(CommandLine $cli, Filesystem $files)
|
||||
/**
|
||||
* Run diagnostics.
|
||||
*/
|
||||
function run($print)
|
||||
function run($print, $plainText)
|
||||
{
|
||||
$this->print = $print;
|
||||
|
||||
$this->beforeRun();
|
||||
|
||||
$result = collect($this->commands)->map(function ($command) {
|
||||
$results = collect($this->commands)->map(function ($command) {
|
||||
$this->beforeCommand($command);
|
||||
|
||||
$output = $this->cli->runAsUser($command);
|
||||
|
||||
$this->afterCommand($command, $output);
|
||||
|
||||
return implode(PHP_EOL, ["$ $command", trim($output)]);
|
||||
})->implode(PHP_EOL.str_repeat('-', 25).PHP_EOL);
|
||||
return compact('command', 'output');
|
||||
});
|
||||
|
||||
$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');
|
||||
|
||||
@@ -117,4 +119,21 @@ function afterCommand($command, $output)
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,14 +537,15 @@
|
||||
/**
|
||||
* 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...');
|
||||
|
||||
Diagnose::run($print);
|
||||
Diagnose::run($print, $plain);
|
||||
|
||||
info('Diagnostics output has been copied to your clipboard.');
|
||||
})->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',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user