{"record":{"id":"12c6051ef0bf3942","repo":"kubernetes/kops","slug":"cannot-mix-name-for-cluster-with-positional-argu","errorCode":null,"errorMessage":"cannot mix --name for cluster with positional arguments","messagePattern":"cannot mix --name for cluster with positional arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_cluster.go","lineNumber":101,"sourceCode":"\t// ClusterNames is a list of cluster names to show; if not specified all clusters will be shown\n\tClusterNames []string\n}\n\nfunc NewCmdGetCluster(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {\n\toptions := GetClusterOptions{\n\t\tGetOptions: getOptions,\n\t}\n\n\tcmd := &cobra.Command{\n\t\tUse:     \"clusters [CLUSTER]...\",\n\t\tAliases: []string{\"cluster\"},\n\t\tShort:   getClusterShort,\n\t\tLong:    getClusterLong,\n\t\tExample: getClusterExample,\n\t\tArgs: func(cmd *cobra.Command, args []string) error {\n\t\t\tif len(args) != 0 {\n\t\t\t\tif rootCommand.clusterName != \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"cannot mix --name for cluster with positional arguments\")\n\t\t\t\t}\n\t\t\t\toptions.ClusterNames = append(options.ClusterNames, args...)\n\t\t\t} else if rootCommand.clusterName != \"\" {\n\t\t\t\toptions.ClusterNames = append(options.ClusterNames, rootCommand.clusterName)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t\tValidArgsFunction: commandutils.CompleteClusterName(f, false, true),\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\treturn RunGetClusters(cmd.Context(), f, out, &options)\n\t\t},\n\t}\n\n\tcmd.Flags().BoolVar(&options.FullSpec, \"full\", options.FullSpec, \"Show fully populated configuration\")\n\n\treturn cmd\n}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_cluster.go#L83-L119","documentation":"The `kops get clusters` command rejects invocations that pass cluster names as positional arguments while also setting a cluster via the global --name flag. The Args validator in cmd/kops/get_cluster.go enforces this mutual exclusivity because both mechanisms select clusters and combining them is ambiguous. It is a pure argument-validation error raised before any cloud or state-store access.","triggerScenarios":"Running e.g. `kops get clusters --name mycluster.example.com mycluster.example.com` or `kops get cluster --name a.example.com b.example.com` — len(args) != 0 and rootCommand.clusterName != \"\".","commonSituations":"Scripts that append a cluster name positionally while KOPS_CLUSTER_NAME (or --name) is exported in the environment; users copying examples that use either style but not both; shell aliases that inject --name automatically.","solutions":["Remove the positional cluster names and rely only on --name: `kops get clusters --name mycluster.example.com`.","Or drop --name and pass names positionally: `kops get cluster mycluster.example.com`.","Unset KOPS_CLUSTER_NAME in the environment if it was set unintentionally (check with `env | grep KOPS`)."],"exampleFix":"// before\nkops get clusters --name mycluster.example.com mycluster.example.com\n// after\nkops get clusters --name mycluster.example.com","handlingStrategy":"validation","validationCode":"args=\"mycluster.example.com\"\nif [ -n \"$KOPS_CLUSTER_NAME\" ] && [ -n \"$args\" ]; then\n  echo \"Cannot mix --name/KOPS_CLUSTER_NAME with positional cluster args\" >&2; exit 1\nfi\nkops get clusters $args","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Pick one selection style per invocation: either --name or positional args, never both.","Avoid exporting KOPS_CLUSTER_NAME in long-lived shell profiles; scope it per script.","Wrap kops calls in scripts that check `env | grep KOPS_CLUSTER_NAME` before adding positional names."],"tags":["cli","argument-validation","kops-get"],"backgroundTag":"conflicting-cli-flags","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}