|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the XabbuhPandaBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xabbuh\PandaBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
15
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
16
|
|
|
use Symfony\Component\Console\Helper\TableHelper; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
use Xabbuh\PandaClient\Exception\PandaException; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Base class of all commands which act on panda clouds. |
|
24
|
|
|
* |
|
25
|
|
|
* The cloud name can be specified on the command-line. If no cloud is |
|
26
|
|
|
* given the configured default cloud is used. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Christian Flothmann <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract class CloudCommand extends ContainerAwareCommand |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
85 |
|
protected function configure() |
|
36
|
|
|
{ |
|
37
|
85 |
|
$this->addOption( |
|
38
|
85 |
|
'cloud', |
|
39
|
85 |
|
'-c', |
|
40
|
85 |
|
InputOption::VALUE_REQUIRED, |
|
41
|
85 |
|
'Cloud on which the command is executed.' |
|
42
|
|
|
); |
|
43
|
85 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return \Xabbuh\PandaClient\Api\CloudManager |
|
47
|
|
|
*/ |
|
48
|
67 |
|
protected function getCloudManager() |
|
49
|
|
|
{ |
|
50
|
67 |
|
return $this->getContainer()->get('xabbuh_panda.cloud_manager'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the cloud to work on. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
57
|
|
|
* |
|
58
|
|
|
* @return \Xabbuh\PandaClient\Api\Cloud |
|
59
|
|
|
*/ |
|
60
|
67 |
|
protected function getCloud(InputInterface $input) |
|
61
|
|
|
{ |
|
62
|
67 |
|
if (null === $input->getOption('cloud')) { |
|
63
|
67 |
|
return $this->getCloudManager()->getDefaultCloud(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $this->getCloudManager()->getCloud($input->getOption('cloud')); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Executes the actual command (to be implemented by subclasses, will be called automatically). |
|
71
|
|
|
* |
|
72
|
|
|
* @param InputInterface $input |
|
73
|
|
|
* @param OutputInterface $output |
|
74
|
|
|
*/ |
|
75
|
|
|
abstract protected function doExecuteCommand(InputInterface $input, OutputInterface $output); |
|
76
|
18 |
|
|
|
77
|
|
|
/** |
|
78
|
18 |
|
* {@inheritDoc} |
|
79
|
18 |
|
*/ |
|
80
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
81
|
|
|
{ |
|
82
|
|
|
try { |
|
83
|
|
|
$this->doExecuteCommand($input, $output); |
|
84
|
|
|
} catch (PandaException $e) { |
|
85
|
|
|
$output->writeln(sprintf('<error>An error occurred: %s</error>', $e->getMessage())); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|