|
2 | 2 |
|
3 | 3 | namespace Leaf\Queue\Commands; |
4 | 4 |
|
5 | | -use Aloe\Command; |
6 | 5 | use Illuminate\Support\Str; |
| 6 | +use Leaf\Sprout\Command; |
7 | 7 |
|
8 | 8 | class GenerateJobCommand extends Command |
9 | 9 | { |
10 | | - protected static $defaultName = 'g:job'; |
11 | | - public $description = 'Create a job class'; |
12 | | - public $help = 'Generate a new job class'; |
13 | | - |
14 | | - protected function config() |
15 | | - { |
16 | | - $this->setArgument('job', 'required', 'job name'); |
17 | | - } |
| 10 | + protected $signature = 'g:job |
| 11 | + {job : job name}'; |
| 12 | + protected $description = 'Create a job class'; |
| 13 | + protected $help = 'Generate a new job class'; |
18 | 14 |
|
19 | 15 | protected function handle() |
20 | 16 | { |
| 17 | + $rootDir = getcwd(); |
21 | 18 | $job = Str::studly(Str::singular($this->argument('job'))); |
22 | 19 |
|
23 | 20 | if (!strpos($job, 'Job')) { |
24 | 21 | $job .= 'Job'; |
25 | 22 | } |
26 | 23 |
|
27 | | - $file = \Aloe\Command\Config::rootpath(AppPaths('jobs') . "/$job.php"); |
| 24 | + $file = $rootDir . DIRECTORY_SEPARATOR . AppPaths('jobs') . "/$job.php"; |
28 | 25 |
|
29 | | - if (!is_dir(\Aloe\Command\Config::rootpath(AppPaths('jobs')))) { |
30 | | - mkdir(\Aloe\Command\Config::rootpath(AppPaths('jobs'))); |
| 26 | + if (!\Leaf\FS\Directory::exists($rootDir . DIRECTORY_SEPARATOR . AppPaths('jobs'))) { |
| 27 | + \Leaf\FS\Directory::create($rootDir . DIRECTORY_SEPARATOR . AppPaths('jobs'), [ |
| 28 | + 'recursive' => true, |
| 29 | + ]); |
31 | 30 | } |
32 | 31 |
|
33 | | - if (file_exists($file)) { |
| 32 | + if (\Leaf\FS\File::exists($file)) { |
34 | 33 | $this->error("$job already exists"); |
35 | 34 |
|
36 | 35 | return 1; |
37 | 36 | } |
38 | 37 |
|
39 | | - touch($file); |
40 | | - |
41 | | - $fileContent = \file_get_contents(__DIR__ . '/stubs/job.stub'); |
42 | | - $fileContent = str_replace('ClassName', $job, $fileContent); |
| 38 | + \Leaf\FS\File::create($file, function () use ($job) { |
| 39 | + $fileContent = \file_get_contents(__DIR__ . '/stubs/job.stub'); |
| 40 | + $fileContent = str_replace('ClassName', $job, $fileContent); |
43 | 41 |
|
44 | | - file_put_contents($file, $fileContent); |
| 42 | + return $fileContent; |
| 43 | + }); |
45 | 44 |
|
46 | 45 | $this->comment("$job generated successfully"); |
47 | 46 |
|
|
0 commit comments