-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added new RunCommand class - Run Soar with the given options - Handle the execution of Soar and display the results
- Loading branch information
Showing
4 changed files
with
112 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/** @noinspection MethodVisibilityInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/laravel-soar. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\LaravelSoar\Commands\Concerns; | ||
|
||
use Guanguans\LaravelSoar\Soar; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* @mixin \Illuminate\Console\Command | ||
*/ | ||
trait WithSoarOptions | ||
{ | ||
protected function configure(): void | ||
{ | ||
$this->setDefinition($this->definition()); | ||
} | ||
|
||
/** | ||
* @return array<\Symfony\Component\Console\Input\InputArgument|\Symfony\Component\Console\Input\InputOption> | ||
*/ | ||
protected function definition(): array | ||
{ | ||
return [ | ||
new InputOption( | ||
'option', | ||
'o', | ||
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, | ||
'The option to be passed to Soar(e.g. `--option=-report-type=markdown` or `--option report-type=markdown` or `-o report-type=markdown`)', | ||
), | ||
]; | ||
} | ||
|
||
protected function debugSoar(): Soar | ||
{ | ||
$soar = $this->soar(); | ||
|
||
if ($this->option('verbose')) { | ||
$soar->dump(); | ||
$this->newLine(); | ||
} | ||
|
||
return $soar; | ||
} | ||
|
||
protected function soar(): Soar | ||
{ | ||
return app(Soar::class)->mergeOptions($this->normalizedSoarOptions()); | ||
} | ||
|
||
protected function normalizedSoarOptions(): array | ||
{ | ||
return collect($this->option('option')) | ||
->mapWithKeys(static function (string $option): array { | ||
[$key, $value] = Str::of($option)->explode('=', 2)->pad(2, null)->all(); | ||
|
||
return [Str::start($key, '-') => $value]; | ||
}) | ||
->all(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the guanguans/laravel-soar. | ||
* | ||
* (c) guanguans <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled. | ||
*/ | ||
|
||
namespace Guanguans\LaravelSoar\Commands; | ||
|
||
use Guanguans\LaravelSoar\Commands\Concerns\WithSoarOptions; | ||
use Illuminate\Console\Command; | ||
|
||
class RunCommand extends Command | ||
{ | ||
use WithSoarOptions; | ||
protected $signature = 'soar:run'; | ||
|
||
protected $description = 'Run Soar with the given options'; | ||
|
||
/** | ||
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException | ||
*/ | ||
public function handle(): void | ||
{ | ||
$this->info($this->debugSoar()->run()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters