|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Cecil/Cecil package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Cecil\Command; |
|
12
|
|
|
|
|
13
|
|
|
use Cecil\Exception\RuntimeException; |
|
14
|
|
|
use Cecil\Util; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Open content with an editor. |
|
22
|
|
|
*/ |
|
23
|
|
|
class OpenWith extends AbstractCommand |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
|
|
->setName('open') |
|
32
|
|
|
->setDescription('Open content with the editor') |
|
33
|
|
|
->setDefinition( |
|
34
|
|
|
new InputDefinition([ |
|
35
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
|
36
|
|
|
]) |
|
37
|
|
|
) |
|
38
|
|
|
->setHelp('Open content directory with the editor defined in the configuration file.)'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
* |
|
44
|
|
|
* @throws RuntimeException |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
47
|
|
|
{ |
|
48
|
|
|
try { |
|
49
|
|
|
if (!$this->hasEditor()) { |
|
50
|
|
|
$output->writeln('<comment>No editor configured.</comment>'); |
|
51
|
|
|
|
|
52
|
|
|
return 0; |
|
53
|
|
|
} |
|
54
|
|
|
$output->writeln(\sprintf('<info>Opening content directory with %s...</info>', (string) $this->getBuilder()->getConfig()->get('editor'))); |
|
55
|
|
|
$this->openEditor(Util::joinFile($this->getPath(), $this->getBuilder()->getConfig()->get('content.dir'))); |
|
|
|
|
|
|
56
|
|
|
} catch (\Exception $e) { |
|
57
|
|
|
throw new RuntimeException(\sprintf($e->getMessage())); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return 0; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|