{"record":{"id":"4fbadf89cd9c25ab","repo":"JanDeDobbeleer/oh-my-posh","slug":"invalid-argument-q-for-s-s-flag-v","errorCode":null,"errorMessage":"invalid argument %q for \"-%s, --%s\" flag: %v","messagePattern":"invalid argument %q for \"-(.+?), --(.+?)\" flag: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdflag/cmdflag.go","lineNumber":351,"sourceCode":"\t\tcase len(shorthands) > 2 && shorthands[1] == '=':\n\t\t\tvalue = shorthands[2:]\n\t\t\tshorthands = \"\"\n\t\tcase flag.Value.Type() == boolType:\n\t\t\tvalue = trueStr\n\t\t\tshorthands = shorthands[1:]\n\t\tcase len(shorthands) > 1:\n\t\t\tvalue = shorthands[1:]\n\t\t\tshorthands = \"\"\n\t\tcase len(rest) > 0:\n\t\t\tvalue = rest[0]\n\t\t\trest = rest[1:]\n\t\t\tshorthands = \"\"\n\t\tdefault:\n\t\t\treturn rest, fmt.Errorf(\"flag needs an argument: %q in -%s\", c, shorthands)\n\t\t}\n\n\t\tif err := flag.Value.Set(value); err != nil {\n\t\t\treturn rest, fmt.Errorf(\"invalid argument %q for \\\"-%s, --%s\\\" flag: %v\", value, flag.Shorthand, flag.Name, err)\n\t\t}\n\n\t\tflag.Changed = true\n\t}\n\n\treturn rest, nil\n}\n\n// usage rendering\n\n// FlagUsages renders the non-hidden flags sorted by name, shorthand column,\n// type name after the flag, defaults in parentheses when they differ from\n// the zero value, usage aligned in a single column.\nfunc (f *FlagSet) FlagUsages() string {\n\tlines := make([]string, 0, len(f.order))\n\tmaxlen := 0\n\n\tflags := make([]*Flag, len(f.order))","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdflag/cmdflag.go#L333-L369","documentation":"Raised when a shorthand's value fails flag.Value.Set during parseShort - the same failure mode as the long form's 'invalid argument' error, but the message shows both the shorthand and the long name. The underlying strconv error from bool/int/float parsing is wrapped as %v.","triggerScenarios":"Parse called with '-fVALUE', '-f=VALUE', or '-f VALUE' where VALUE cannot be parsed by the flag's Value type: e.g. '-p=abc' for an int port flag.","commonSituations":"Typos in numeric values; bool spellings like 'yes'/'on' that strconv.ParseBool rejects; values with whitespace or units from unquoted shell strings; copy-paste introducing invisible characters or smart quotes.","solutions":["Use a value valid for the flag type: true/false/0/1 for bools, digits for int/float.","Inspect the trailing strconv error in the message to see the exact parse failure.","Quote shell values so stray characters don't corrupt them.","If you own the CLI, implement a custom Value whose Set accepts the looser syntax your users expect."],"exampleFix":"// before\nargs := []string{\"-p=8o80\"} // invalid argument \"8o80\" for \"-p, --port\" flag: strconv.ParseInt: parsing \"8o80\": invalid syntax\n// after\nargs := []string{\"-p=8080\"}","handlingStrategy":"validation","validationCode":"func validNumeric(s string, base int) bool {\n    _, err := strconv.ParseInt(s, base, 64)\n    return err == nil\n}\n// guard before invoking: if !validNumeric(port, 10) { return fmt.Errorf(\"port %q must be an integer\", port) }","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"invalid argument\") && strings.Contains(err.Error(), \"flag:\") {\n        // message includes value, -short, --long name and strconv cause\n        fmt.Fprintf(os.Stderr, \"%v\\n\", err)\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Sanitize numeric inputs (strip spaces, units, thousands separators) before passing.","Use only strconv-compatible bool literals: true/false/0/1/t/f/T/F/TRUE/FALSE.","Quote values in shell to prevent hidden characters and glob expansion.","Test script invocations with representative values, not just defaults."],"tags":["cli","flag-parsing","type-conversion","shorthand"],"backgroundTag":"invalid-flag-argument","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}