From 84c33a0adc3f7f204b867c742c79bbac6293c9c4 Mon Sep 17 00:00:00 2001 From: jerguslejko Date: Mon, 3 Feb 2020 21:53:19 +0000 Subject: [PATCH 1/2] add --execute option to console command --- src/Console/TinkerCommand.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Console/TinkerCommand.php b/src/Console/TinkerCommand.php index 9853285..235cc20 100644 --- a/src/Console/TinkerCommand.php +++ b/src/Console/TinkerCommand.php @@ -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 { @@ -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 { @@ -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 bit of code inside Tinker'], + ]; + } } From 859d33080f7833301f38e52a8f51615151b85fc4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 4 Feb 2020 17:13:06 -0600 Subject: [PATCH 2/2] Update TinkerCommand.php --- src/Console/TinkerCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/TinkerCommand.php b/src/Console/TinkerCommand.php index 235cc20..3202ab6 100644 --- a/src/Console/TinkerCommand.php +++ b/src/Console/TinkerCommand.php @@ -147,7 +147,7 @@ protected function getArguments() protected function getOptions() { return [ - ['execute', null, InputOption::VALUE_OPTIONAL, 'Execute the given bit of code inside Tinker'], + ['execute', null, InputOption::VALUE_OPTIONAL, 'Execute the given code using Tinker'], ]; } }