{"record":{"id":"eaab3977ce08d264","repo":"kubernetes/kops","slug":"cannot-specify-cluster-via-name-and-positional-a","errorCode":null,"errorMessage":"cannot specify cluster via --name and positional argument","messagePattern":"cannot specify cluster via --name and positional argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/root.go","lineNumber":303,"sourceCode":"\t\tif c.clusterName == \"\" {\n\t\t\tc.clusterName = args[0]\n\t\t\treturn nil\n\t\t}\n\t}\n\n\tfmt.Printf(\"\\nFound multiple arguments which look like a cluster name\\n\")\n\tif c.clusterName != \"\" {\n\t\tfmt.Printf(\"\\t%q (via flag)\\n\", c.clusterName)\n\t}\n\tfor _, arg := range args {\n\t\tfmt.Printf(\"\\t%q (as argument)\\n\", arg)\n\t}\n\tfmt.Printf(\"\\n\")\n\tfmt.Printf(\"This often happens if you specify an argument to a boolean flag without using =\\n\")\n\tfmt.Printf(\"For example: use `--bastion=true` or `--bastion`, not `--bastion true`\\n\\n\")\n\n\tif len(args) == 1 {\n\t\treturn fmt.Errorf(\"cannot specify cluster via --name and positional argument\")\n\t}\n\treturn fmt.Errorf(\"expected a single <clustername> to be passed as an argument\")\n}\n\nfunc (c *RootCmd) ClusterName(verbose bool) string {\n\tif c.clusterName != \"\" {\n\t\treturn c.clusterName\n\t}\n\n\t// Read from kubeconfig\n\tpathOptions := clientcmd.NewDefaultPathOptions()\n\n\tconfig, err := pathOptions.GetStartingConfig()\n\tif err != nil {\n\t\tklog.Warningf(\"error reading kubecfg: %v\", err)\n\t} else if config.CurrentContext == \"\" {\n\t\tklog.Warningf(\"no context set in kubecfg\")\n\t} else {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/root.go#L285-L321","documentation":"RootCmd.ProcessArgs parses positional args under the rule: zero args OK, or exactly one arg used as the cluster name when --name was not set. If exactly one arg was given but --name is already set, the cluster is specified twice — ProcessArgs returns \"cannot specify cluster via --name and positional argument\" after printing a diagnostic listing both values and hinting at the boolean-flag pitfall.","triggerScenarios":"A command receives len(args)==1 while c.clusterName is non-empty (i.e. --name was also provided). E.g. `kops get cluster --name a.k8s.local b.k8s.local`. Also triggered indirectly when a boolean flag was given a bare value (e.g. `--bastion true`), making `true` the positional arg.","commonSituations":"`--flag value` instead of `--flag=value` for booleans, so \"true\" becomes the cluster name; combining --name with a positional cluster name in scripts; passing a leftover token from shell word-splitting.","solutions":["Remove either --name or the positional cluster argument — specify the cluster only once","If a boolean flag was involved, use `--bastion=true` / `--bastion` syntax instead of `--bastion true`","Quote/skip an unintended extra argument in the script (check for accidental variables expanding to a string)","If you intended to change the cluster, drop the positional arg and only use --name"],"exampleFix":"// before\nkops get cluster --name a.k8s.local b.k8s.local\n// error: cannot specify cluster via --name and positional argument\n// after\nkops get cluster --name a.k8s.local","handlingStrategy":"validation","validationCode":"// precheck: never combine --name with a positional cluster\nif clusterFlag != \"\" && len(positionalArgs) >= 1 {\n    return errors.New(\"specify the cluster once: use --name OR positional argument, not both\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use --flag=value syntax for boolean flags so values are not parsed as args","Pick one convention (always --name) across all automation","Review scripts for stray positional tokens from variable expansion","Read the kops diagnostic output — it lists the conflicting values"],"tags":["cli-flags","argument-parsing","cluster-name"],"backgroundTag":"conflicting-arguments","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"}