diff --git a/CHANGELOG.md b/CHANGELOG.md index 85aff291..cc85694d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ dev-master - [mixin] Node mxin remove does not accept a path +### Enhancements + +- [exit] Ask for confirmation before logging out when there are pending changes + alpha-5 ------- diff --git a/features/shell_exit.feature b/features/shell_exit.feature new file mode 100644 index 00000000..86bd3add --- /dev/null +++ b/features/shell_exit.feature @@ -0,0 +1,12 @@ +Feature: Exit the shell + In order to quit this damned shell + As a user + I want to be able to execute a command which does that. + + Background: + Given that I am logged in as "testuser" + + Scenario: Make a change and attempt to exist (default to no exit) + Given I execute the "node:create foo" command + And I execute the "shell:exit --no-interaction" command + Then the command should not fail diff --git a/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php b/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php index f662f433..492c8458 100644 --- a/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php +++ b/src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php @@ -16,7 +16,23 @@ public function configure() public function execute(InputInterface $input, OutputInterface $output) { - $this->getHelper('phpcr')->getSession()->logout(); + $dialog = $this->getHelper('dialog'); + $session = $this->getHelper('phpcr')->getSession(); + $noInteraction = $input->getOption('no-interaction'); + + if ($session->hasPendingChanges()) { + $res = false; + + if ($input->isInteractive()) { + $res = $dialog->askConfirmation($output, 'Session has pending changes, are you sure you want to quit? (Y/N)', false); + } + + if (false === $res) { + return; + } + } + + $session->logout(); $output->writeln('Bye!'); exit(0); }