|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the dotfiles project. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Anthonius Munthi <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Dotfiles\Core; |
|
15
|
|
|
|
|
16
|
|
|
use Dotfiles\Core\Config\Config; |
|
17
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
|
|
22
|
|
|
class Application extends BaseApplication |
|
23
|
|
|
{ |
|
24
|
|
|
public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; |
|
25
|
|
|
|
|
26
|
|
|
public const RELEASE_DATE = '@release_date@'; |
|
27
|
|
|
|
|
28
|
|
|
public const VERSION = '@package_version@'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Config |
|
32
|
|
|
*/ |
|
33
|
|
|
private $config; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var InputInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $input; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var OutputInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
private $output; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
Config $config, |
|
50
|
|
|
InputInterface $input, |
|
51
|
|
|
OutputInterface $output |
|
52
|
|
|
) { |
|
53
|
|
|
parent::__construct('dotfiles', static::VERSION); |
|
54
|
|
|
|
|
55
|
|
|
$this->config = $config; |
|
56
|
|
|
$this->input = $input; |
|
57
|
|
|
$this->output = $output; |
|
58
|
|
|
|
|
59
|
|
|
$this->getDefinition()->addOption( |
|
60
|
|
|
new InputOption('dry-run', '-d', InputOption::VALUE_NONE, 'Only show which files would have been modified') |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getLongVersion() |
|
68
|
|
|
{ |
|
69
|
|
|
return implode(' ', array( |
|
70
|
|
|
static::VERSION, |
|
71
|
|
|
static::BRANCH_ALIAS_VERSION, |
|
72
|
|
|
static::RELEASE_DATE, |
|
73
|
|
|
)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null) |
|
80
|
|
|
{ |
|
81
|
|
|
if (null === $input) { |
|
82
|
|
|
$input = $this->input; |
|
83
|
|
|
} |
|
84
|
|
|
if (null === $output) { |
|
85
|
|
|
$output = $this->output; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$dryRun = $input->hasParameterOption(array('--dry-run'), true); |
|
89
|
|
|
$this->config->set('dotfiles.dry_run', $dryRun); |
|
90
|
|
|
|
|
91
|
|
|
global $argv; |
|
92
|
|
|
$isCompile = false; |
|
93
|
|
|
if (isset($argv[1])) { |
|
94
|
|
|
$isCompile = 'compile' === $argv[1] || '--version' == $argv[1] ? true : false; |
|
95
|
|
|
} |
|
96
|
|
|
if ( |
|
97
|
|
|
!getenv('DOTFILES_BACKUP_DIR') |
|
98
|
|
|
&& ('dev' !== getenv('DOTFILES_ENV')) |
|
99
|
|
|
&& !$isCompile |
|
100
|
|
|
) { |
|
101
|
|
|
return $this->find('init')->run($input, $output); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return parent::run($input, $output); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|