{"record":{"id":"2507a87915d8b1dc","repo":"JanDeDobbeleer/oh-my-posh","slug":"invalid-argument-q-for-s-flag-v","errorCode":null,"errorMessage":"invalid argument %q for \"--%s\" flag: %v","messagePattern":"invalid argument %q for \"--(.+?)\" flag: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdflag/cmdflag.go","lineNumber":304,"sourceCode":"\t\t\treturn rest[1:], nil\n\t\t}\n\n\t\treturn rest, nil\n\t}\n\n\tswitch {\n\tcase hasValue:\n\tcase flag.Value.Type() == boolType:\n\t\tvalue = trueStr\n\tcase len(rest) > 0:\n\t\tvalue = rest[0]\n\t\trest = rest[1:]\n\tdefault:\n\t\treturn rest, fmt.Errorf(\"flag needs an argument: --%s\", name)\n\t}\n\n\tif err := flag.Value.Set(value); err != nil {\n\t\treturn rest, fmt.Errorf(\"invalid argument %q for \\\"--%s\\\" flag: %v\", value, flag.Name, err)\n\t}\n\n\tflag.Changed = true\n\treturn rest, nil\n}\n\nfunc (f *FlagSet) parseShort(shorthands string, rest []string) ([]string, error) {\n\tfor len(shorthands) > 0 {\n\t\tc := shorthands[0]\n\n\t\tflag := f.shorthands[c]\n\t\tif flag == nil {\n\t\t\tif f.ParseErrorsAllowlist.UnknownFlags {\n\t\t\t\t// drop the remainder of the group and a\n\t\t\t\t// separate value token unless it is itself a flag\n\t\t\t\tif len(shorthands) == 1 && len(rest) > 0 && !strings.HasPrefix(rest[0], \"-\") {\n\t\t\t\t\treturn rest[1:], nil\n\t\t\t\t}","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdflag/cmdflag.go#L286-L322","documentation":"Raised when the value supplied to a long flag fails flag.Value.Set. The parser found a value (via =, or the next token), but converting it failed - e.g. ParseBool rejecting 'yes' for a bool flag, or ParseInt rejecting 'abc' for an int flag. The original Set error is wrapped into the message with the value and flag name.","triggerScenarios":"Parse called with '--flag=value' where value is invalid for the flag's registered type (boolValue, intValue, float64Value): e.g. '--debug=1x' for a bool, '--threads=ten' for an int.","commonSituations":"Users passing Go-unfriendly bool spellings (yes/no/on/off instead of true/false/1/0); copy-pasting values with units ('4s' into an int flag); locale-formatted numbers with commas; scripts interpolating empty strings ('--port=' with int parse error).","solutions":["Supply a value parseable for the flag's type: true/false/1/0 for bools, plain integers for int, numeric for float.","Read the wrapped %v error at the end of the message - it names the exact parse failure from strconv.","Fix shell quoting so stray characters or empty strings don't reach the parser.","Change the flag's Value implementation to accept the input format if you control the CLI (custom Value type with tolerant Set)."],"exampleFix":"// before\nomp args: \"--debug=yes\" -> invalid argument \"yes\" for \"--debug\" flag: strconv.ParseBool: parsing \"yes\": invalid syntax\n// after\nargs := []string{\"--debug=true\"} // or just \"--debug\"","handlingStrategy":"validation","validationCode":"func validateFlagValue(typ, val string) error {\n    switch typ {\n    case \"bool\":\n        if _, err := strconv.ParseBool(val); err != nil {\n            return fmt.Errorf(\"%q is not a valid bool (use true/false/1/0)\", val)\n        }\n    case \"int\":\n        if _, err := strconv.ParseInt(val, 0, 64); err != nil {\n            return fmt.Errorf(\"%q is not a valid integer\", val)\n        }\n    case \"float64\":\n        if _, err := strconv.ParseFloat(val, 64); err != nil {\n            return fmt.Errorf(\"%q is not a valid float\", val)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if i := strings.Index(err.Error(), \"invalid argument \"); i == 0 {\n        // message already contains value, flag, and the strconv cause\n        fmt.Fprintf(os.Stderr, \"%v\\nRun with --help for accepted formats.\\n\", err)\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Use true/false/1/0 for bool flags - not yes/no/on/off.","Strip units and whitespace from numeric values before passing them.","Quote shell arguments to keep stray characters out of values.","Read the wrapped strconv error at the end of the message; it names the exact parse failure."],"tags":["cli","flag-parsing","type-conversion"],"backgroundTag":"invalid-flag-argument","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}