Skip to content

Instantly share code, notes, and snippets.

@mauricius
Created January 9, 2019 15:37
Show Gist options
  • Save mauricius/0e8dcdde18ce9744bd3258e8f0c24f34 to your computer and use it in GitHub Desktop.
Save mauricius/0e8dcdde18ce9744bd3258e8f0c24f34 to your computer and use it in GitHub Desktop.
Print a recap of a Laravel/Symphony command before executing
<?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