Skip to content

Commit

Permalink
Merge pull request #89 from jerguslejko/execute-option
Browse files Browse the repository at this point in the history
[2.x] Add --execute option to console command
  • Loading branch information
taylorotwell authored Feb 4, 2020
2 parents d8ce361 + 859d330 commit ca586a7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Console/TinkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psy\Configuration;
use Psy\Shell;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class TinkerCommand extends Command
{
Expand Down Expand Up @@ -64,6 +65,14 @@ public function handle()

$loader = ClassAliasAutoloader::register($shell, $path);

if ($code = $this->option('execute')) {
$shell->execute($code);

$loader->unregister();

return 0;
}

try {
$shell->run();
} finally {
Expand Down Expand Up @@ -129,4 +138,16 @@ protected function getArguments()
['include', InputArgument::IS_ARRAY, 'Include file(s) before starting tinker'],
];
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['execute', null, InputOption::VALUE_OPTIONAL, 'Execute the given code using Tinker'],
];
}
}

0 comments on commit ca586a7

Please sign in to comment.