From 86fa6493620d0f87f8e126d8f50dc8f812c980d6 Mon Sep 17 00:00:00 2001 From: Aryeh Raber Date: Sat, 25 Apr 2020 16:29:53 +0200 Subject: [PATCH] Format output using
+ and add plain text flag to opt out --- cli/Valet/Diagnose.php | 29 ++++++++++++++++++++++++----- cli/valet.php | 7 ++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cli/Valet/Diagnose.php b/cli/Valet/Diagnose.php index 731c456..7c74acf 100644 --- a/cli/Valet/Diagnose.php +++ b/cli/Valet/Diagnose.php @@ -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( + '
%s%s%s
%s
%s
', + PHP_EOL, $command, PHP_EOL, $output, PHP_EOL + ); + })->implode($plainText ? PHP_EOL.str_repeat('-', 20).PHP_EOL : PHP_EOL); + } } diff --git a/cli/valet.php b/cli/valet.php index ae358ac..099007c 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -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', ]); }