{"record":{"id":"3b89e53f26719b9c","repo":"kubernetes/kops","slug":"expected-a-single-clustername-to-be-passed-as-an","errorCode":null,"errorMessage":"expected a single <clustername> to be passed as an argument","messagePattern":"expected a single <clustername> to be passed as an argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/root.go","lineNumber":305,"sourceCode":"\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 {\n\t\tcontext := config.Contexts[config.CurrentContext]\n\t\tif context == nil {","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/root.go#L287-L323","documentation":"ProcessArgs' final error: more than one positional argument was supplied where at most one (<clustername>) is allowed. Before returning, kops prints all received arguments and the common boolean-flag pitfall (`--bastion true` vs `--bastion=true`). This guards against silently misinterpreting extra tokens as cluster names.","triggerScenarios":"The command receives len(args) >= 2, e.g. `kops delete cluster a.k8s.local extra`, or a boolean flag consumed a value leaving multiple stray tokens as positional args (e.g. `kops update cluster --bastion yes a.k8s.local`).","commonSituations":"Accidentally passing multiple cluster names; unquoted strings with spaces becoming multiple args; `--flag value` misuse on booleans inserting the value into args; copy-pasted commands with extra tokens.","solutions":["Reduce to a single positional <clustername> (or use --name and no positional args)","For boolean flags use `--flag=true` syntax so the value is not parsed as a positional argument","Quote strings containing spaces so they don't split into multiple args","Echo the command in scripts to verify what tokens are actually being passed"],"exampleFix":"// before\nkops update cluster --bastion yes mycluster.k8s.local\n// error: expected a single <clustername> to be passed as an argument\n// after\nkops update cluster mycluster.k8s.local --bastion=true","handlingStrategy":"validation","validationCode":"// precheck argument count before invoking kops\nif len(args) > 1 {\n    return fmt.Errorf(\"kops accepts at most one positional <clustername>; got %d: %v\", len(args), args)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote arguments containing spaces","Use --flag=true for booleans instead of --flag yes/true as separate tokens","Shellcheck scripts that build kops command lines dynamically","Keep one cluster per command invocation; loop over clusters explicitly"],"tags":["cli-flags","argument-parsing","cluster-name"],"backgroundTag":"too-many-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"}