Skip to content

Commit a11690a

Browse files
committed
Alias list and config reload commands
1 parent b9908e4 commit a11690a

File tree

7 files changed

+99
-7
lines changed

7 files changed

+99
-7
lines changed

features/shell_alias.feature

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Feature: Default aliases
1+
Feature: Command aliases
22
In order to be more effective when using the shell
33
As a user
44
I want to be able to use the default command aliases
@@ -22,3 +22,14 @@ Feature: Default aliases
2222
| ls cms |
2323
| sl cms foobar |
2424
| cat cms |
25+
26+
Scenario: List aliases
27+
Given I execute the "shell:alias:list" command
28+
Then the command should not fail
29+
And I should see a table containing the following rows:
30+
| Alias | Command |
31+
| cd | shell:path:change {arg1} |
32+
| ls | node:list {arg1} |
33+
34+
35+

features/shell_config_reload.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: Reload the configuration
2+
In order to reload the configuration
3+
As a user
4+
I want to be able to execute a command which does that
5+
6+
Scenario: Reload configuration
7+
Given I execute the "shell:config:reload" command
8+
Then the command should not fail

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ private function registerCommands()
215215
$this->add(new CommandPhpcr\LockUnlockCommand());
216216

217217
// add shell-specific commands
218+
$this->add(new CommandShell\AliasListCommand());
218219
$this->add(new CommandShell\ConfigInitCommand());
220+
$this->add(new CommandShell\ConfigReloadCommand());
219221
$this->add(new CommandShell\PathChangeCommand());
220222
$this->add(new CommandShell\PathShowCommand());
221223
$this->add(new CommandShell\ExitCommand());
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command\Shell;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
class AliasListCommand extends Command
10+
{
11+
public function configure()
12+
{
13+
$this->setName('shell:alias:list');
14+
$this->setDescription('List all the registered aliases');
15+
$this->setHelp(<<<EOT
16+
EOT
17+
);
18+
}
19+
20+
public function execute(InputInterface $input, OutputInterface $output)
21+
{
22+
$config = $this->getHelper('config');
23+
$aliases = $config->getConfig('alias');
24+
25+
$table = clone $this->getHelper('table');
26+
$table->setHeaders(array('Alias', 'Command'));
27+
28+
foreach ($aliases as $alias => $command) {
29+
$table->addRow(array($alias, $command));
30+
}
31+
32+
$table->render($output);
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command\Shell;
4+
5+
use Symfony\Component\Filesystem\Filesystem;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class ConfigReloadCommand extends Command
11+
{
12+
protected $output;
13+
14+
public function configure()
15+
{
16+
$this->setName('shell:config:reload');
17+
$this->setDescription('Reload the configuration');
18+
$this->setHelp(<<<EOT
19+
Reload the configuration
20+
EOT
21+
);
22+
}
23+
24+
public function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$this->output = $output;
27+
$config = $this->getHelper('config');
28+
$config->loadConfig();
29+
}
30+
}

src/PHPCR/Shell/Console/Helper/ConfigHelper.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public function getConfigDir()
7373
return $home;
7474
}
7575

76-
private function loadConfig()
76+
/**
77+
* Load the configuration
78+
*/
79+
public function loadConfig()
7780
{
7881
$config = array();
7982

@@ -88,6 +91,8 @@ private function loadConfig()
8891
}
8992
}
9093

94+
$this->cachedConfig = $config;
95+
9196
return $config;
9297
}
9398

@@ -99,11 +104,10 @@ private function loadConfig()
99104
public function getConfig($type)
100105
{
101106
if (null !== $this->cachedConfig) {
102-
return $this->cachedConfig['alias'];
107+
return $this->cachedConfig[$type];
103108
}
104109

105-
$this->cachedConfig = $this->loadConfig();
106-
107-
return $this->cachedConfig['alias'];
110+
$this->loadConfig();
111+
return $this->cachedConfig[$type];
108112
}
109113
}

src/PHPCR/Shell/Resources/config.dist/alias.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# Shell shortcuts
2+
aliases: shell:alias:list
3+
14
# MySQL commands
25
use: workspace:use
36
workspaces: workspace:list
47
select: query:select
58

69
# Filesystem commands
710
cd: shell:path:change {arg1}
8-
rm: node:delete {arg1}
11+
rm: node:remove {arg1}
912
mv: node:move {arg1} {arg2}
1013
pwd: shell:path:show
1114
exit: shell:exit

0 commit comments

Comments
 (0)