mirror of https://github.com/kubernetes/kops.git
Merge pull request #180 from justinsb/delete_cluster_positional_arg
kops delete cluster now recognizes clustername as a positional arg
This commit is contained in:
commit
aa51cfa967
|
@ -23,11 +23,11 @@ var deleteCluster DeleteClusterCmd
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "cluster",
|
Use: "cluster CLUSTERNAME [--yes]",
|
||||||
Short: "Delete cluster",
|
Short: "Delete cluster",
|
||||||
Long: `Deletes a k8s cluster.`,
|
Long: `Deletes a k8s cluster.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := deleteCluster.Run()
|
err := deleteCluster.Run(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Exitf("%v", err)
|
glog.Exitf("%v", err)
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,13 @@ func init() {
|
||||||
|
|
||||||
type getter func(o interface{}) interface{}
|
type getter func(o interface{}) interface{}
|
||||||
|
|
||||||
func (c *DeleteClusterCmd) Run() error {
|
func (c *DeleteClusterCmd) Run(args []string) error {
|
||||||
var clusterRegistry *api.ClusterRegistry
|
var clusterRegistry *api.ClusterRegistry
|
||||||
var err error
|
|
||||||
|
err := rootCommand.ProcessArgs(args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var cloud fi.Cloud
|
var cloud fi.Cloud
|
||||||
clusterName := ""
|
clusterName := ""
|
||||||
|
@ -55,7 +59,7 @@ func (c *DeleteClusterCmd) Run() error {
|
||||||
if c.External {
|
if c.External {
|
||||||
region = c.Region
|
region = c.Region
|
||||||
if region == "" {
|
if region == "" {
|
||||||
return fmt.Errorf("--region is required")
|
return fmt.Errorf("--region is required (when --external)")
|
||||||
}
|
}
|
||||||
clusterName = rootCommand.clusterName
|
clusterName = rootCommand.clusterName
|
||||||
if clusterName == "" {
|
if clusterName == "" {
|
||||||
|
|
|
@ -79,6 +79,26 @@ func (c *RootCmd) AddCommand(cmd *cobra.Command) {
|
||||||
c.cobraCommand.AddCommand(cmd)
|
c.cobraCommand.AddCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessArgs will parse the positional args. It assumes one of these formats:
|
||||||
|
// * <no arguments at all>
|
||||||
|
// * <clustername> (and --name not specified)
|
||||||
|
// Everything else is an error.
|
||||||
|
func (c *RootCmd) ProcessArgs(args []string) error {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(args) == 1 {
|
||||||
|
// Assume <clustername>
|
||||||
|
if c.clusterName != "" {
|
||||||
|
return fmt.Errorf("Cannot specify cluster via --name and positional argument")
|
||||||
|
}
|
||||||
|
c.clusterName = args[0]
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("expected a single <clustername> to be passed as an argument")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *RootCmd) ClusterName() string {
|
func (c *RootCmd) ClusterName() string {
|
||||||
if c.clusterName != "" {
|
if c.clusterName != "" {
|
||||||
return c.clusterName
|
return c.clusterName
|
||||||
|
|
Loading…
Reference in New Issue