{"record":{"id":"b316eda1f655721c","repo":"ahmetb/kubectx","slug":"unsupported-arguments-q","errorCode":null,"errorMessage":"unsupported arguments %q","messagePattern":"unsupported arguments %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/kubens/flags.go","lineNumber":67,"sourceCode":"\t\tcase \"--help\", \"-h\":\n\t\t\treturn HelpOp{}\n\t\tcase \"--version\", \"-V\":\n\t\t\treturn VersionOp{}\n\t\tcase \"--current\", \"-c\":\n\t\t\treturn CurrentOp{}\n\t\tcase \"--unset\", \"-u\":\n\t\t\treturn UnsetOp{}\n\t\tdefault:\n\t\t\treturn getSwitchOp(v, false)\n\t\t}\n\t} else if n == 2 {\n\t\t// {namespace} -f|--force\n\t\tname := argv[0]\n\t\tforce := slices.Contains([]string{\"-f\", \"--force\"}, argv[1])\n\n\t\tif !force {\n\t\t\tif !slices.Contains([]string{\"-f\", \"--force\"}, argv[0]) {\n\t\t\t\treturn UnsupportedOp{Err: fmt.Errorf(\"unsupported arguments %q\", argv)}\n\t\t\t}\n\n\t\t\t// -f|--force {namespace}\n\t\t\tforce = true\n\t\t\tname = argv[1]\n\t\t}\n\n\t\treturn getSwitchOp(name, force)\n\t}\n\n\treturn UnsupportedOp{Err: fmt.Errorf(\"too many arguments\")}\n}\n\nfunc getSwitchOp(v string, force bool) Op {\n\tif strings.HasPrefix(v, \"-\") && v != \"-\" {\n\t\treturn UnsupportedOp{Err: fmt.Errorf(\"unsupported option %q\", v)}\n\t}\n\treturn SwitchOp{Target: v, Force: force}","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/flags.go#L49-L85","documentation":"parseArgs validates kubens command-line arguments for the rename/force forms. When the arguments neither match \"{namespace} -f|--force\" nor \"-f|--force {namespace}\" (nor a plain namespace switch), it returns UnsupportedOp with \"unsupported arguments %q\" listing the raw argv. This is a usage error, not a runtime failure.","triggerScenarios":"Calling kubens with two arguments where neither is -f/--force, e.g. `kubens foo bar`, or a single stray flag like `kubens -x`.","commonSituations":"Typos in the namespace name combined with flags; users guessing at flag syntax; shell scripts passing extra positional arguments; confusing kubens flags with kubectl's.","solutions":["Use the documented forms: `kubens <namespace>` or `kubens -f <namespace>` (or `kubens <namespace> -f`)","Run `kubens --help` to see accepted argument shapes","Quote the namespace name to prevent the shell from splitting it into multiple args","Remove unintended extra arguments from scripts calling kubens"],"exampleFix":"// before\nkubens foo bar\n// after\nkubens foo            # plain switch\nkubens -f foo         # force switch","handlingStrategy":"validation","validationCode":"args := os.Args[1:]\nvalid := len(args) == 1 ||\n    (len(args) == 2 && (args[0] == \"-f\" || args[0] == \"--force\" || args[1] == \"-f\" || args[1] == \"--force\"))\nif !valid {\n    return fmt.Errorf(\"usage: kubens [-f] <namespace>\")\n}","typeGuard":null,"tryCatchPattern":"op := kubens.ParseArgs(argv)\nif uo, ok := op.(kubens.UnsupportedOp); ok {\n    fmt.Fprintf(stderr, \"usage error: %v\\n\", uo.Err)\n    os.Exit(2) // usage error, not runtime failure\n}","preventionTips":["Quote namespace names in shell scripts","Use only documented forms: kubens [-f] <namespace>","Check UnsupportedOp type before executing parsed ops","Keep flag syntax distinct from kubectl's"],"tags":["cli","usage","argument-parsing","go"],"backgroundTag":"unsupported-cli-arguments","analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}