-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmd.go
52 lines (44 loc) · 1.78 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
52
// Copyright Contributors to the Open Cluster Management project
package clusterclaim
import (
"fmt"
genericclioptionscm "github.com/stolostron/cm-cli/pkg/genericclioptions"
"github.com/stolostron/cm-cli/pkg/helpers"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
clusteradmhelpers "open-cluster-management.io/clusteradm/pkg/helpers"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
var example = `
# Use a cluster
%[1]s with cc <cluster_claim_name>
# Use a cluster on a given clusterpoolhosts
%[1]s with cc <cluster_claim_name> --cph <cluster_pool_host_name>
`
// NewCmd provides a cobra command for using a cluster claim
func NewCmd(cmFlags *genericclioptionscm.CMFlags, streams genericclioptions.IOStreams) *cobra.Command {
o := newOptions(cmFlags, streams)
cmd := &cobra.Command{
Use: "clusterclaim",
Aliases: []string{"clusterclaims", "cc", "ccs"},
Short: "with clusterclaim executes a kubernetes command using the clusterclaim context",
Long: "with clusterclaim executes a kubernetes command using the clusterclaim context, optionally the cluster pool host can be provided to override the current one",
Example: fmt.Sprintf(example, helpers.GetExampleHeader()),
SilenceUsage: true,
PreRunE: func(c *cobra.Command, args []string) error {
clusteradmhelpers.DryRunMessage(cmFlags.DryRun)
return nil
},
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.complete(cmd, args))
cmdutil.CheckErr(o.validate())
cmdutil.CheckErr(o.run())
},
FParseErrWhitelist: cobra.FParseErrWhitelist{
UnknownFlags: true,
},
}
cmd.Flags().StringVar(&o.ClusterPoolHost, "cph", "", "The clusterpoolhost to use")
cmd.Flags().IntVar(&o.Timeout, "timeout", 60, "Timeout to wait the cluster claim running")
return cmd
}