Skip to content

Commit b3ed4a2

Browse files
committed
Various improvements
- Allow multiple commands to be specified from command line (good for debugging) - Show the full stack trace on commands executed with --verbose
1 parent 83c1e8f commit b3ed4a2

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

box.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"alias": "phpcr.phar",
2+
"alias": "phpcrsh.phar",
33
"chmod": "0755",
44
"directories": ["src"],
55
"files": [
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"git-version": "package_version",
16-
"main": "bin/phpcr",
17-
"output": "phpcr.phar",
16+
"main": "bin/phpcrsh",
17+
"output": "phpcrsh.phar",
1818
"stub": true
1919
}

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
288288
try {
289289
$exitCode = parent::doRun($input, $output);
290290
} catch (\Exception $e) {
291-
$this->dispatcher->dispatch(PhpcrShellEvents::COMMAND_EXCEPTION, new Event\CommandExceptionEvent($e, $output));
291+
$this->dispatcher->dispatch(PhpcrShellEvents::COMMAND_EXCEPTION, new Event\CommandExceptionEvent($e, $input, $output));
292292

293293
return 1;
294294
}

src/PHPCR/Shell/Console/Command/ShellCommand.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Console\Input\InputOption;
99
use PHPCR\Shell\Console\Application\ShellApplication;
1010
use PHPCR\Shell\Console\Application\Shell;
11-
use Symfony\Component\Console\Input\StringInput;
11+
use PHPCR\Shell\Console\Input\StringInput;
1212

1313
/**
1414
* The shell command is the command used to configure the shell session
@@ -63,7 +63,7 @@ public function configure()
6363

6464
new InputOption('--profile', '-p', InputOption::VALUE_OPTIONAL, 'Speicfy a profile name, use wit <info>--transport</info> to update or create'),
6565
new InputOption('--unsupported', null, InputOption::VALUE_NONE, 'Show all commands, including commands not supported by the repository'),
66-
new InputOption('--command', null, InputOption::VALUE_REQUIRED, 'Run the given command'),
66+
new InputOption('--command', null, InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Run the given command'),
6767
));
6868
}
6969

@@ -80,10 +80,14 @@ public function execute(InputInterface $input, OutputInterface $output)
8080

8181
$noInteraction = $input->getOption('no-interaction');
8282

83-
if ($command = $input->getOption('command')) {
83+
if ($commands = $input->getOption('command')) {
8484
$application->setCatchExceptions(false);
85-
$input = new StringInput($command);
86-
$application->run($input, $output);
85+
$application->setAutoExit(false);
86+
87+
foreach ($commands as $command) {
88+
$input = new StringInput($command);
89+
$application->run($input, $output);
90+
}
8791

8892
return;
8993
} else {

src/PHPCR/Shell/Event/CommandExceptionEvent.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44

55
use Symfony\Component\EventDispatcher\Event;
66
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Input\InputInterface;
78

89
class CommandExceptionEvent extends Event
910
{
1011
protected $exception;
1112
protected $output;
13+
protected $input;
1214

13-
public function __construct(\Exception $exception, OutputInterface $output)
15+
public function __construct(\Exception $exception, InputInterface $input, OutputInterface $output)
1416
{
1517
$this->exception = $exception;
1618
$this->output = $output;
19+
$this->input = $input;
1720
}
1821

1922
public function getException()
@@ -25,4 +28,9 @@ public function getOutput()
2528
{
2629
return $this->output;
2730
}
31+
32+
public function getInput()
33+
{
34+
return $this->input;
35+
}
2836
}

src/PHPCR/Shell/Subscriber/ExceptionSubscriber.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ public static function getSubscribedEvents()
2525
public function handleException(CommandExceptionEvent $event)
2626
{
2727
$exception = $event->getException();
28+
$input = $event->getInput();
2829
$output = $event->getOutput();
2930

31+
// if verbose, just throw the whole exception back
32+
if ($input->hasOption('verbose') && $input->getOption('verbose')) {
33+
throw $exception;
34+
}
35+
36+
3037
if ($exception instanceof UnsupportedRepositoryOperationException) {
3138
$output->writeln('<error>Unsupported repository operation: This repository is not capable of performing the requested action</error>');
3239
}

0 commit comments

Comments
 (0)