|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dotfiles\Core\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\COnsole\Input\InputOption; |
|
9
|
|
|
use Dotfiles\Core\Util\Toolkit; |
|
10
|
|
|
use Dotfiles\Core\Util\Filesystem; |
|
11
|
|
|
|
|
12
|
|
|
class AddCommand extends Command implements CommandInterface |
|
13
|
|
|
{ |
|
14
|
|
|
protected function configure() |
|
15
|
|
|
{ |
|
16
|
|
|
$this |
|
17
|
|
|
->setName('add') |
|
18
|
|
|
->setDescription('Add new file into dotfiles manager') |
|
19
|
|
|
->addArgument('path', InputArgument::REQUIRED,'A file or directory name to add. This file must be exists in $HOME directory') |
|
20
|
|
|
->addOption('machine','-m', InputOption::VALUE_OPTIONAL, 'Add this file/directory into machine registry','default') |
|
21
|
|
|
->addOption('recursive','-r', InputOption::VALUE_NONE, 'Import all directory contents recursively') |
|
22
|
|
|
; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
26
|
|
|
{ |
|
27
|
|
|
$recursive = $input->getOption('recursive'); |
|
|
|
|
|
|
28
|
|
|
$machine = $input->getOption('machine'); |
|
29
|
|
|
$dir = getcwd()."/templates/$machine/home"; |
|
30
|
|
|
$sourcePath = $input->getArgument("path"); |
|
31
|
|
|
$source = getenv("HOME").DIRECTORY_SEPARATOR.$sourcePath; |
|
32
|
|
|
|
|
33
|
|
|
if(!is_file($source)){ |
|
34
|
|
|
throw new \InvalidArgumentException("Path <comment>$sourcePath</comment> not exists"); |
|
35
|
|
|
} |
|
36
|
|
|
Toolkit::ensureDir($dir); |
|
37
|
|
|
|
|
38
|
|
|
$fs = new Filesystem(); |
|
39
|
|
|
$fs->copy($source, $dir."/".$sourcePath); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|