|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\Terminal\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
|
|
9
|
|
|
class Vi extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The console command name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name = 'vi'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Vi Editor'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* $files. |
|
27
|
|
|
* |
|
28
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $files; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* __construct. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Illuminate\Filesystem\Filesystem $files |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(Filesystem $files) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct(); |
|
40
|
|
|
|
|
41
|
|
|
$this->files = $files; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Handle the command. |
|
46
|
|
|
* |
|
47
|
|
|
* @throws \InvalidArgumentException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function handle() |
|
50
|
|
|
{ |
|
51
|
|
|
$path = $this->argument('path'); |
|
52
|
|
|
$text = $this->option('text'); |
|
53
|
|
|
$root = function_exists('base_path') === true ? base_path() : getcwd(); |
|
54
|
|
|
$path = rtrim($root, '/').'/'.$path; |
|
55
|
|
|
|
|
56
|
|
|
if (is_null($text) === false) { |
|
57
|
|
|
$this->files->put($path, $text); |
|
58
|
|
|
} else { |
|
59
|
|
|
$this->line($this->files->get($path)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the console command arguments. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getArguments() |
|
69
|
|
|
{ |
|
70
|
|
|
return [ |
|
71
|
|
|
['path', InputArgument::REQUIRED, 'path'], |
|
72
|
|
|
]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the console command options. |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function getOptions() |
|
81
|
|
|
{ |
|
82
|
|
|
return [ |
|
83
|
|
|
['text', null, InputOption::VALUE_OPTIONAL], |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|