Skip to content

Ask confirmation before exiting when there are pending changes #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
12 changes: 12 additions & 0 deletions features/shell_exit.feature
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion src/PHPCR/Shell/Console/Command/Shell/ExitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<question>Session has pending changes, are you sure you want to quit? (Y/N)</question>', false);
}

if (false === $res) {
return;
}
}

$session->logout();
$output->writeln('<info>Bye!</info>');
exit(0);
}
Expand Down