-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathShellCommand.php
123 lines (103 loc) · 5.28 KB
/
ShellCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace PHPCR\Shell\Console\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use PHPCR\Shell\Console\Application\ShellApplication;
use PHPCR\Shell\Console\Application\Shell;
use PHPCR\Shell\Console\Input\StringInput;
use Symfony\Component\Console\Input\InputArgument;
use PHPCR\Shell\Console\Descriptor\RstDescriptor;
/**
* The shell command is the command used to configure the shell session
*
* @author Daniel Leech <[email protected]>
*/
class ShellCommand extends Command
{
/**
* @var ShellApplication
*/
protected $application;
/**
* Constructor - construct with the shell application. This
* command provides the connection parameters (by simply passing
* the Input object).
*
* @param ShellApplication $application
*/
public function __construct(ShellApplication $application)
{
$this->application = $application;
parent::__construct();
}
/**
* {@inheritDoc}
*/
public function configure()
{
$this->setName('phpcr_shell');
$this->setDefinition(array(
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version.'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
new InputOption('--transport', '-t', InputOption::VALUE_REQUIRED, 'Transport to use.'),
new InputOption('--phpcr-username', '-pu', InputOption::VALUE_REQUIRED, 'PHPCR Username.', 'admin'),
new InputOption('--phpcr-password', '-pp', InputOption::VALUE_OPTIONAL, 'PHPCR Password.', 'admin'),
new InputOption('--db-username', '-du', InputOption::VALUE_REQUIRED, 'Database Username.', 'root'),
new InputOption('--db-name', '-dn', InputOption::VALUE_REQUIRED, 'Database Name.', 'phpcr'),
new InputOption('--db-password', '-dp', InputOption::VALUE_OPTIONAL, 'Database Password.'),
new InputOption('--db-host', '-dh', InputOption::VALUE_REQUIRED, 'Database Host.', 'localhost'),
new InputOption('--db-driver', '-dd', InputOption::VALUE_REQUIRED, 'Database Transport.', 'pdo_mysql'),
new InputOption('--db-path', '-dP', InputOption::VALUE_REQUIRED, 'Database Path.'),
new InputOption('--no-interaction', null, InputOption::VALUE_NONE, 'Turn off interaction (for testing purposes)'),
new InputOption('--repo-url', '-url', InputOption::VALUE_REQUIRED, 'URL of repository (e.g. for jackrabbit).', 'http://localhost:8080/server/'),
new InputOption('--repo-path', '-path', InputOption::VALUE_REQUIRED, 'Path to repository (e.g. for Jackalope FS).', '/home/myuser/www/myproject/app/data'),
new InputOption('--profile', '-p', InputOption::VALUE_OPTIONAL, 'Speicfy a profile name, use wit <info>--transport</info> to update or create'),
new InputOption('--unsupported', null, InputOption::VALUE_NONE, 'Show all commands, including commands not supported by the repository'),
new InputOption('--command', null, InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Run the given command'),
new InputOption('--reference', null, InputOption::VALUE_NONE, 'Dump a complete command reference in RST format'),
new InputArgument('workspace', InputArgument::OPTIONAL, 'Workspace to start with', 'default')
));
}
/**
* {@inheritDoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$showUnspported = $input->getOption('unsupported');
$noInteraction = $input->getOption('no-interaction');
$dumpReference = $input->getOption('reference');
$application = $this->application;
$application->setShowUnsupported($showUnspported);
$application->dispatchProfileInitEvent($input, $output);
if ($input->getOption('verbose')) {
$application->setDebug(true);
}
$noInteraction = $input->getOption('no-interaction');
if ($commands = $input->getOption('command')) {
$application->setCatchExceptions(false);
$application->setAutoExit(false);
foreach ($commands as $command) {
$input = new StringInput($command);
$application->run($input, $output);
}
return;
} else {
$application = new Shell($this->application);
}
if ($dumpReference) {
$this->application->init();
$descriptor = new RstDescriptor();
$descriptor->describe($output, $this->application);
return 0;
}
if ($noInteraction) {
return 0;
}
$application->run($output);
}
}