-
Notifications
You must be signed in to change notification settings - Fork 2
/
job_make_command.go
66 lines (51 loc) · 1.62 KB
/
job_make_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package console
import (
"errors"
"os"
"strings"
"github.com/gookit/color"
"github.com/oarkflow/framework/contracts/console"
"github.com/oarkflow/framework/contracts/console/command"
"github.com/oarkflow/framework/support/file"
"github.com/oarkflow/framework/support/str"
)
type JobMakeCommand struct {
}
// Signature The name and signature of the console command.
func (receiver *JobMakeCommand) Signature() string {
return "make:job"
}
// Description The console command description.
func (receiver *JobMakeCommand) Description() string {
return "Create a new job class"
}
// Extend The console command extend.
func (receiver *JobMakeCommand) Extend() command.Extend {
return command.Extend{
Category: "make",
}
}
// Handle Execute the console command.
func (receiver *JobMakeCommand) Handle(ctx console.Context) error {
name := ctx.Argument(0)
if name == "" {
return errors.New("Not enough arguments (missing: name) ")
}
file.Create(receiver.getPath(name), receiver.populateStub(receiver.getStub(), name))
color.Greenln("Job created successfully")
return nil
}
func (receiver *JobMakeCommand) getStub() string {
return JobStubs{}.Job()
}
// populateStub Populate the place-holders in the command stub.
func (receiver *JobMakeCommand) populateStub(stub string, name string) string {
stub = strings.ReplaceAll(stub, "DummyJob", str.Case2Camel(name))
stub = strings.ReplaceAll(stub, "DummyName", str.Camel2Case(name))
return stub
}
// getPath Get the full path to the command.
func (receiver *JobMakeCommand) getPath(name string) string {
pwd, _ := os.Getwd()
return pwd + "/app/jobs/" + str.Camel2Case(name) + ".go"
}