Skip to content

Commit 7d5c01e

Browse files
committed
Merge pull request #95 from phpcr/exit-ask-confirmation
Ask confirmation before exiting when there are pending changes
2 parents 9e8961f + 6578952 commit 7d5c01e

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ dev-master
88

99
- [mixin] Node mxin remove does not accept a path
1010

11+
### Enhancements
12+
13+
- [exit] Ask for confirmation before logging out when there are pending changes
14+
1115
alpha-5
1216
-------
1317

features/shell_exit.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Exit the shell
2+
In order to quit this damned shell
3+
As a user
4+
I want to be able to execute a command which does that.
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
9+
Scenario: Make a change and attempt to exist (default to no exit)
10+
Given I execute the "node:create foo" command
11+
And I execute the "shell:exit --no-interaction" command
12+
Then the command should not fail

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ public function configure()
1616

1717
public function execute(InputInterface $input, OutputInterface $output)
1818
{
19-
$this->getHelper('phpcr')->getSession()->logout();
19+
$dialog = $this->getHelper('dialog');
20+
$session = $this->getHelper('phpcr')->getSession();
21+
$noInteraction = $input->getOption('no-interaction');
22+
23+
if ($session->hasPendingChanges()) {
24+
$res = false;
25+
26+
if ($input->isInteractive()) {
27+
$res = $dialog->askConfirmation($output, '<question>Session has pending changes, are you sure you want to quit? (Y/N)</question>', false);
28+
}
29+
30+
if (false === $res) {
31+
return;
32+
}
33+
}
34+
35+
$session->logout();
2036
$output->writeln('<info>Bye!</info>');
2137
exit(0);
2238
}

0 commit comments

Comments
 (0)