-
Notifications
You must be signed in to change notification settings - Fork 61
/
cmd.go
50 lines (41 loc) · 1.27 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
// Copyright Contributors to the Open Cluster Management project
package work
import (
"fmt"
"open-cluster-management.io/clusteradm/pkg/helpers"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
genericclioptionsclusteradm "open-cluster-management.io/clusteradm/pkg/genericclioptions"
)
var example = `
# Delete work in specified cluster
%[1]s delete work work-example --cluster cluster1
`
// NewCmd ...
func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *cobra.Command {
o := newOptions(clusteradmFlags, streams)
cmd := &cobra.Command{
Use: "work",
Short: "delete work in specified cluster",
Example: fmt.Sprintf(example, helpers.GetExampleHeader()),
SilenceUsage: true,
PreRun: func(c *cobra.Command, args []string) {
helpers.DryRunMessage(o.ClusteradmFlags.DryRun)
},
RunE: func(c *cobra.Command, args []string) error {
if err := o.complete(c, args); err != nil {
return err
}
if err := o.validate(); err != nil {
return err
}
if err := o.run(); err != nil {
return err
}
return nil
},
}
o.ClusterOptions.AddFlags(cmd.Flags())
cmd.Flags().BoolVar(&o.Force, "force", false, "set force flag to enable force delete")
return cmd
}