Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
80.00% |
16 / 20 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
CrudTemplate | |
80.00% |
16 / 20 |
|
66.67% |
2 / 3 |
7.39 | |
0.00% |
0 / 1 |
handle | |
69.23% |
9 / 13 |
|
0.00% |
0 / 1 |
5.73 | |||
getOptions | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getArguments | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace San\Crud\Commands; |
4 | |
5 | use Illuminate\Console\Command; |
6 | use San\Crud\Utils\FileUtils; |
7 | use Symfony\Component\Console\Input\InputArgument; |
8 | use Symfony\Component\Console\Input\InputOption; |
9 | |
10 | class CrudTemplate extends CrudBase { |
11 | /** |
12 | * The name and signature of the console command. |
13 | * |
14 | * @var string |
15 | */ |
16 | protected $name = 'crud:template'; |
17 | |
18 | /** |
19 | * The console command description. |
20 | * |
21 | * @var string |
22 | */ |
23 | protected $description = 'Creates a new template for CRUD generation'; |
24 | |
25 | /** |
26 | * Execute the console command. |
27 | * |
28 | * @return int |
29 | */ |
30 | public function handle() { |
31 | $base = base_path($this->option('output') ?: 'templates'); |
32 | $dest = sprintf('%s/%s', $base, $this->argument('name')); |
33 | $force = $this->option('force'); |
34 | |
35 | if (is_dir($dest) && !$force) { |
36 | $this->error("Template '$dest' already exists"); |
37 | return Command::FAILURE; |
38 | } |
39 | |
40 | $src = realpath(__DIR__ . '/../template'); |
41 | if (!is_dir($src)) { |
42 | $this->error("Template source '$src' not found"); |
43 | return Command::FAILURE; |
44 | } |
45 | |
46 | $count = FileUtils::recursiveCopy($src, $dest, $force); |
47 | $this->info("Created $count files in '$dest'"); |
48 | |
49 | return Command::SUCCESS; |
50 | } |
51 | |
52 | protected function getOptions() { |
53 | return [ |
54 | ['output', 'o', InputOption::VALUE_REQUIRED, 'Output directory name (default: "templates")'], |
55 | ['force', 'f', InputOption::VALUE_NONE, 'Overwrite existing files'], |
56 | ]; |
57 | } |
58 | |
59 | /** |
60 | * {@inheritdoc} |
61 | */ |
62 | protected function getArguments() { |
63 | return [ |
64 | ['name', InputArgument::REQUIRED, 'The name of the new template'], |
65 | ]; |
66 | } |
67 | } |