Created
January 9, 2019 15:37
-
-
Save mauricius/0e8dcdde18ce9744bd3258e8f0c24f34 to your computer and use it in GitHub Desktop.
Print a recap of a Laravel/Symphony command before executing
This file contains hidden or 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
<?php | |
class RecapCommand extends Command | |
{ | |
public function handle() | |
{ | |
$this->recapCommand(); | |
if (! $this->confirm('Do you wish to continue?')) | |
{ | |
$this->error('Abort!'); | |
return; | |
} | |
// ... | |
} | |
protected function recapCommand() | |
{ | |
$this->info($this->getDescription()); | |
$header = ['Parameter', 'Description', 'Value']; | |
$body = array_merge( | |
array_map(function ($argument) | |
{ | |
return [$argument->getName(), $argument->getDescription(), $this->argument($argument->getName())]; | |
}, $this->getDefinition()->getArguments()), | |
array_map(function ($option) | |
{ | |
return [$option->getName(), $option->getDescription(), $this->option($option->getName())]; | |
}, $this->getDefinition()->getOptions()) | |
); | |
$this->table($header, $body); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment