@@ -29,39 +29,43 @@ import (
29
29
"github.com/yomorun/yomo/pkg/log"
30
30
)
31
31
32
- var lang string
32
+ var (
33
+ sfnType string
34
+ lang string
35
+ )
33
36
34
37
// initCmd represents the init command
35
38
var initCmd = & cobra.Command {
36
- Use : "init" ,
39
+ Use : "init <app_name> " ,
37
40
Short : "Initialize a YoMo Stream function" ,
38
41
Long : "Initialize a YoMo Stream function" ,
39
42
Run : func (cmd * cobra.Command , args []string ) {
40
- name := opts . Name
43
+ name := ""
41
44
if len (args ) >= 1 && args [0 ] != "" {
42
45
name = args [0 ]
46
+ opts .Name = name
43
47
}
44
-
45
48
if name == "" {
46
- log .FailureStatusEvent (os .Stdout , "Please input your app name" )
49
+ log .FailureStatusEvent (os .Stdout , "Please input your app name, e.g. `yomo init my-app [-l go -t llm]` " )
47
50
return
48
51
}
49
-
50
52
log .PendingStatusEvent (os .Stdout , "Initializing the Stream Function..." )
51
53
name = strings .ReplaceAll (name , " " , "_" )
54
+
52
55
filename := filepath .Join (name , DefaultSFNSourceFile (lang ))
53
56
opts .Filename = filename
54
- // serverless setup
55
- err := serverless .Setup (& opts )
57
+
58
+ // create app source file
59
+ fname := filepath .Join (name , DefaultSFNSourceFile (lang ))
60
+ contentTmpl , err := template .GetContent ("init" , sfnType , lang , false )
56
61
if err != nil {
57
- log .FailureStatusEvent (os .Stdout , err .Error ())
62
+ log .FailureStatusEvent (os .Stdout , "%s" , err .Error ())
58
63
return
59
64
}
60
- // create app source file
61
- fname := filepath .Join (name , DefaultSFNSourceFile (lang ))
62
- contentTmpl , err := template .GetContent ("init" , "" , lang , false )
65
+ // serverless setup
66
+ err = serverless .Setup (& opts )
63
67
if err != nil {
64
- log .FailureStatusEvent (os .Stdout , err .Error ())
68
+ log .FailureStatusEvent (os .Stdout , "%s" , err .Error ())
65
69
return
66
70
}
67
71
if err := file .PutContents (fname , contentTmpl ); err != nil {
@@ -70,10 +74,10 @@ var initCmd = &cobra.Command{
70
74
}
71
75
// create app test file
72
76
testName := filepath .Join (name , DefaultSFNTestSourceFile (lang ))
73
- testTmpl , err := template .GetContent ("init" , "" , lang , true )
77
+ testTmpl , err := template .GetContent ("init" , sfnType , lang , true )
74
78
if err != nil {
75
79
if ! errors .Is (err , template .ErrUnsupportedTest ) {
76
- log .FailureStatusEvent (os .Stdout , err .Error ())
80
+ log .FailureStatusEvent (os .Stdout , "%s" , err .Error ())
77
81
return
78
82
}
79
83
} else {
@@ -98,6 +102,6 @@ var initCmd = &cobra.Command{
98
102
func init () {
99
103
rootCmd .AddCommand (initCmd )
100
104
101
- initCmd .Flags ().StringVarP (& opts . Name , "name " , "n " , "" , "The name of Stream Function" )
105
+ initCmd .Flags ().StringVarP (& sfnType , "type " , "t " , "llm " , "The type of Stream Function, support normal and llm " )
102
106
initCmd .Flags ().StringVarP (& lang , "lang" , "l" , "go" , "The language of Stream Function, support go and node" )
103
107
}
0 commit comments