-
Notifications
You must be signed in to change notification settings - Fork 77
/
cmd.go
51 lines (40 loc) · 1.36 KB
/
cmd.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
package create
import (
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
"kusionstack.io/kusion/pkg/cmd/util"
"kusionstack.io/kusion/pkg/util/i18n"
)
func NewCmd() *cobra.Command {
var (
short = i18n.T(`Create a new project`)
long = i18n.T(`
This command creates a new project.yaml file under the target directory which by default is the current working directory.
Note that the target directory needs to be an empty directory.`)
example = i18n.T(`
# Create a new project with the name of the current working directory
mkdir my-project && cd my-project
kusion project create
# Create a new project in a specified target directory
kusion project create --target /dir/to/projects/my-project`)
)
o := NewOptions()
cmd := &cobra.Command{
Use: "create",
Short: short,
Long: templates.LongDesc(long),
Example: templates.Examples(example),
DisableFlagsInUseLine: true,
RunE: func(cmd *cobra.Command, args []string) (err error) {
// TODO: when a panic occurs, the created project.yaml file needs to be cleaned up.
defer util.RecoverErr(&err)
util.CheckErr(o.Complete(args))
util.CheckErr(o.Validate())
util.CheckErr(o.Run())
return
},
}
cmd.Flags().StringVarP(&o.ProjectDir, "target", "t", "",
i18n.T("specify the target directory"))
return cmd
}