-
Notifications
You must be signed in to change notification settings - Fork 4
/
get.go
62 lines (50 loc) · 1.47 KB
/
get.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
package project
import (
"os"
"github.com/fuseml/fuseml-core/pkg/cli/client"
"github.com/fuseml/fuseml-core/pkg/cli/common"
"github.com/spf13/cobra"
)
// GetOptions holds the options for 'project get' sub command
type GetOptions struct {
client.Clients
global *common.GlobalOptions
format *common.FormattingOptions
Name string
}
// NewGetOptions creates a ProjectGetOptions struct
func NewGetOptions(o *common.GlobalOptions) *GetOptions {
res := &GetOptions{global: o}
res.format = common.NewSingleValueFormattingOptions()
return res
}
// NewSubCmdProjectGet creates and returns the cobra command for the `project get` CLI command
func NewSubCmdProjectGet(gOpt *common.GlobalOptions) *cobra.Command {
o := NewGetOptions(gOpt)
cmd := &cobra.Command{
Use: `get {-n|--name NAME}`,
Short: "Get projects.",
Long: `Show details about a 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")
o.format.AddSingleValueFormattingFlags(cmd, common.FormatYAML)
cmd.MarkFlagRequired("name")
return cmd
}
func (o *GetOptions) validate() error {
return nil
}
func (o *GetOptions) run() error {
project, err := o.ProjectClient.Get(o.Name)
if err != nil {
return err
}
o.format.FormatValue(os.Stdout, project)
return nil
}