-
Notifications
You must be signed in to change notification settings - Fork 4
/
create.go
64 lines (52 loc) · 1.67 KB
/
create.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
package project
import (
"fmt"
"github.com/fuseml/fuseml-core/pkg/cli/client"
"github.com/fuseml/fuseml-core/pkg/cli/common"
"github.com/spf13/cobra"
)
// CreateOptions holds the options for 'project get' sub command
type CreateOptions struct {
client.Clients
global *common.GlobalOptions
format *common.FormattingOptions
Name string
Description string
}
// NewCreateOptions creates a ProjectCreateOptions struct
func NewCreateOptions(o *common.GlobalOptions) *CreateOptions {
res := &CreateOptions{global: o}
res.format = common.NewSingleValueFormattingOptions()
return res
}
// NewSubCmdProjectCreate creates and returns the cobra command for the `project get` CLI command
func NewSubCmdProjectCreate(gOpt *common.GlobalOptions) *cobra.Command {
o := NewCreateOptions(gOpt)
cmd := &cobra.Command{
Use: `create {-n|--name NAME} {-d|--desc DESCRIPTION} [flags]`,
Short: "Create projects.",
Long: `Create new FuseML project`,
Run: func(cmd *cobra.Command, args []string) {
common.CheckErr(o.InitializeClients(gOpt.URL, gOpt.Timeout, gOpt.Verbose))
common.CheckErr(o.validate())
common.CheckErr(o.run())
},
Args: cobra.ExactArgs(0),
}
cmd.Flags().StringVarP(&o.Name, "name", "n", "", "project name")
cmd.Flags().StringVarP(&o.Description, "desc", "d", "", "project description")
o.format.AddSingleValueFormattingFlags(cmd, common.FormatYAML)
cmd.MarkFlagRequired("name")
return cmd
}
func (o *CreateOptions) validate() error {
return nil
}
func (o *CreateOptions) run() error {
_, err := o.ProjectClient.Create(o.Name, o.Description)
if err != nil {
return err
}
fmt.Printf("Project %s successfully created.\n", o.Name)
return nil
}