-
Notifications
You must be signed in to change notification settings - Fork 4
/
delete.go
58 lines (46 loc) · 1.36 KB
/
delete.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
package project
import (
"fmt"
"github.com/fuseml/fuseml-core/pkg/cli/client"
"github.com/fuseml/fuseml-core/pkg/cli/common"
"github.com/spf13/cobra"
)
// DeleteOptions holds the options for 'project delete' sub command
type DeleteOptions struct {
client.Clients
global *common.GlobalOptions
Name string
}
// NewDeleteOptions creates a ProjectDeleteOptions struct
func NewDeleteOptions(o *common.GlobalOptions) *DeleteOptions {
return &DeleteOptions{global: o}
}
// NewSubCmdProjectDelete creates and returns the cobra command for the `project delete` CLI command
func NewSubCmdProjectDelete(gOpt *common.GlobalOptions) *cobra.Command {
o := NewDeleteOptions(gOpt)
cmd := &cobra.Command{
Use: `delete {-n|--name NAME}`,
Short: "Delete projects.",
Long: `Delete a project from FuseML`,
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.MarkFlagRequired("name")
return cmd
}
func (o *DeleteOptions) validate() error {
return nil
}
func (o *DeleteOptions) run() error {
err := o.ProjectClient.Delete(o.Name)
if err != nil {
return err
}
fmt.Printf("Project %s successfully deleted\n", o.Name)
return nil
}