-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAbstractCommand.php
More file actions
74 lines (64 loc) · 2.03 KB
/
Copy pathAbstractCommand.php
File metadata and controls
74 lines (64 loc) · 2.03 KB
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
<?php
namespace LF\EnvDiff\Console\Command;
use LF\EnvDiff\Config;
use LF\EnvDiff\IO\ConsoleIO;
use LF\EnvDiff\Processor;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
abstract class AbstractCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->addArgument('dist', InputOption::VALUE_REQUIRED, 'From file', Config::DEFAULT_DIST)
->addArgument('target', InputOption::VALUE_REQUIRED, 'To file', Config::DEFAULT_TARGET)
->addOption('remove-outdated', 'r', InputOption::VALUE_NONE, 'Remove old env variables');
}
/**
* {@inheritdoc}
*
* @throws InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = $this->createConfig($input);
$processor = $this->createProcessor($input, $output);
$this->doExecute($processor, $config);
return 0;
}
/**
* @param InputInterface $input
*
* @return Config
*
* @throws InvalidArgumentException
*/
private function createConfig(InputInterface $input)
{
$dist = $input->getArgument('dist');
$target = $input->getArgument('target');
$removeOutdated = $input->getOption('remove-outdated');
return new Config($dist, $target, !$removeOutdated);
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return Processor
*/
private function createProcessor(InputInterface $input, OutputInterface $output)
{
return new Processor(new ConsoleIO($input, $output));
}
/**
* @param Processor $processor
* @param Config $config
*/
abstract protected function doExecute(Processor $processor, Config $config);
}