mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	cmd: refactor common err expr into helper function
The same redundant fmt.Sprintf() and string literal was duplicated throughout many of the files in kubectl/cmd. Replace with a helper function.
This commit is contained in:
		@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -77,7 +76,7 @@ func CreateClusterRoleBinding(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Co
 | 
				
			|||||||
			ServiceAccounts: cmdutil.GetFlagStringArray(cmd, "serviceaccount"),
 | 
								ServiceAccounts: cmdutil.GetFlagStringArray(cmd, "serviceaccount"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -97,7 +96,7 @@ func CreateConfigMap(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, ar
 | 
				
			|||||||
			EnvFileSource:  cmdutil.GetFlagString(cmd, "from-env-file"),
 | 
								EnvFileSource:  cmdutil.GetFlagString(cmd, "from-env-file"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -92,7 +92,7 @@ func createDeployment(f cmdutil.Factory, cmdOut, cmdErr io.Writer, cmd *cobra.Co
 | 
				
			|||||||
	case cmdutil.DeploymentBasicV1Beta1GeneratorName:
 | 
						case cmdutil.DeploymentBasicV1Beta1GeneratorName:
 | 
				
			||||||
		generator = &kubectl.DeploymentBasicGeneratorV1{Name: name, Images: cmdutil.GetFlagStringSlice(cmd, "image")}
 | 
							generator = &kubectl.DeploymentBasicGeneratorV1{Name: name, Images: cmdutil.GetFlagStringSlice(cmd, "image")}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -69,7 +68,7 @@ func CreateNamespace(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, ar
 | 
				
			|||||||
	case cmdutil.NamespaceV1GeneratorName:
 | 
						case cmdutil.NamespaceV1GeneratorName:
 | 
				
			||||||
		generator = &kubectl.NamespaceGeneratorV1{Name: name}
 | 
							generator = &kubectl.NamespaceGeneratorV1{Name: name}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -89,7 +88,7 @@ func CreatePodDisruptionBudget(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.C
 | 
				
			|||||||
			Selector:       cmdutil.GetFlagString(cmd, "selector"),
 | 
								Selector:       cmdutil.GetFlagString(cmd, "selector"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -78,7 +77,7 @@ func CreateQuota(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, args [
 | 
				
			|||||||
			Scopes: cmdutil.GetFlagString(cmd, "scopes"),
 | 
								Scopes: cmdutil.GetFlagString(cmd, "scopes"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -78,7 +77,7 @@ func CreateRoleBinding(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command,
 | 
				
			|||||||
			ServiceAccounts: cmdutil.GetFlagStringArray(cmd, "serviceaccount"),
 | 
								ServiceAccounts: cmdutil.GetFlagStringArray(cmd, "serviceaccount"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -110,7 +109,7 @@ func CreateSecretGeneric(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command
 | 
				
			|||||||
			EnvFileSource:  cmdutil.GetFlagString(cmd, "from-env-file"),
 | 
								EnvFileSource:  cmdutil.GetFlagString(cmd, "from-env-file"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
@@ -191,7 +190,7 @@ func CreateSecretDockerRegistry(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.
 | 
				
			|||||||
			Server:   cmdutil.GetFlagString(cmd, "docker-server"),
 | 
								Server:   cmdutil.GetFlagString(cmd, "docker-server"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
@@ -254,7 +253,7 @@ func CreateSecretTLS(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, ar
 | 
				
			|||||||
			Cert: cmdutil.GetFlagString(cmd, "cert"),
 | 
								Cert: cmdutil.GetFlagString(cmd, "cert"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -83,6 +82,10 @@ func NewCmdCreateServiceClusterIP(f cmdutil.Factory, cmdOut io.Writer) *cobra.Co
 | 
				
			|||||||
	return cmd
 | 
						return cmd
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func errUnsupportedGenerator(cmd *cobra.Command, generatorName string) error {
 | 
				
			||||||
 | 
						return cmdutil.UsageError(cmd, "Generator %s not supported. ", generatorName)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CreateServiceClusterIP implements the behavior to run the create service clusterIP command
 | 
					// CreateServiceClusterIP implements the behavior to run the create service clusterIP command
 | 
				
			||||||
func CreateServiceClusterIP(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, args []string) error {
 | 
					func CreateServiceClusterIP(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, args []string) error {
 | 
				
			||||||
	name, err := NameFromCommandArgs(cmd, args)
 | 
						name, err := NameFromCommandArgs(cmd, args)
 | 
				
			||||||
@@ -99,7 +102,7 @@ func CreateServiceClusterIP(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Comm
 | 
				
			|||||||
			ClusterIP: cmdutil.GetFlagString(cmd, "clusterip"),
 | 
								ClusterIP: cmdutil.GetFlagString(cmd, "clusterip"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
@@ -156,7 +159,7 @@ func CreateServiceNodePort(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Comma
 | 
				
			|||||||
			NodePort:  cmdutil.GetFlagInt(cmd, "node-port"),
 | 
								NodePort:  cmdutil.GetFlagInt(cmd, "node-port"),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
@@ -211,7 +214,7 @@ func CreateServiceLoadBalancer(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.C
 | 
				
			|||||||
			ClusterIP: "",
 | 
								ClusterIP: "",
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
@@ -272,7 +275,7 @@ func CreateExternalNameService(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.C
 | 
				
			|||||||
			ClusterIP:    "",
 | 
								ClusterIP:    "",
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
				
			|||||||
package cmd
 | 
					package cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
@@ -69,7 +68,7 @@ func CreateServiceAccount(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Comman
 | 
				
			|||||||
	case cmdutil.ServiceAccountV1GeneratorName:
 | 
						case cmdutil.ServiceAccountV1GeneratorName:
 | 
				
			||||||
		generator = &kubectl.ServiceAccountGeneratorV1{Name: name}
 | 
							generator = &kubectl.ServiceAccountGeneratorV1{Name: name}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
 | 
							return errUnsupportedGenerator(cmd, generatorName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
						return RunCreateSubcommand(f, cmd, cmdOut, &CreateSubcommandOptions{
 | 
				
			||||||
		Name:                name,
 | 
							Name:                name,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user