Skip to content

Commit 7030c1d

Browse files
committed
feat: implement job generate
1 parent d4eb162 commit 7030c1d

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

src/Queue/Commands/GenerateJobCommand.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,42 @@
33
namespace Leaf\Queue\Commands;
44

55
use Aloe\Command;
6+
use Illuminate\Support\Str;
67

78
class GenerateJobCommand extends Command
89
{
910
protected static $defaultName = 'g:job';
10-
public $description = 'Generate a job class';
11-
public $help = 'Generate a job class';
11+
public $description = 'Create a job class';
12+
public $help = 'Generate a new job class';
1213

1314
protected function config()
1415
{
15-
$this->setArgument('job', 'required');
16+
$this->setArgument('job', 'required', 'job name');
1617
}
1718

1819
protected function handle()
1920
{
20-
$job = $this->argument('config');
21+
$job = Str::studly(Str::singular($this->argument('job')));
2122

22-
$this->writeln("Generating job $job");
23+
if (!strpos($job, 'Job')) {
24+
$job .= 'Job';
25+
}
26+
27+
$file = \Aloe\Command\Config::rootpath(AppPaths('jobs') . "/$job.php");
28+
29+
if (file_exists($file)) {
30+
$this->error("$job already exists");
31+
return 1;
32+
}
33+
34+
touch($file);
35+
36+
$fileContent = \file_get_contents(__DIR__ . '/stubs/job.stub');
37+
$fileContent = str_replace('ClassName', $job, $fileContent);
38+
39+
file_put_contents($file, $fileContent);
40+
41+
$this->comment("$job generated successfully");
42+
return 0;
2343
}
2444
}

0 commit comments

Comments
 (0)