{"record":{"id":"dff8b8b52eb4394b","repo":"JanDeDobbeleer/oh-my-posh","slug":"flag-needs-an-argument-s","errorCode":null,"errorMessage":"flag needs an argument: --%s","messagePattern":"flag needs an argument: --(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdflag/cmdflag.go","lineNumber":300,"sourceCode":"\n\t\t// an unknown flag given as \"--flag value\" swallows the\n\t\t// value token unless the next token is itself a flag\n\t\tif !hasValue && len(rest) > 0 && !strings.HasPrefix(rest[0], \"-\") {\n\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","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdflag/cmdflag.go#L282-L318","documentation":"Raised by parseLong when a registered non-bool long flag is given without a value: not via '--flag=value', and no following token remains to consume as the value. The parser has nothing to pass to flag.Value.Set, so it errors. Bool flags are exempt because their bare presence implies true.","triggerScenarios":"Calling Parse with a trailing '--name' where 'name' is a registered string/int/float flag and it is the last argument, e.g. Parse([]string{\"--config\"}).","commonSituations":"Shell variable expansion producing an empty value (\"--config $EMPTY_VAR\" collapses to \"--config\"); scripts accidentally dropping the value; users forgetting '=value' when they expected the equals form; quoting mistakes splitting the value into a separate consumed positional.","solutions":["Pass the value inline: use --flag=value or --flag value with the value present as the next token.","Check shell quoting/expansion so an empty variable doesn't remove the value token.","If the flag should be optional-with-default, don't pass it at all; the registered default applies.","For bool-like toggles, register the flag as a bool so it can be used bare."],"exampleFix":"// before\nargs := []string{\"--config\"} // flag needs an argument: --config\n// after\nargs := []string{\"--config\", \"~/.posh.toml\"} // or \"--config=$HOME/.posh.toml\"","handlingStrategy":"validation","validationCode":"func hasValueToken(args []string) error {\n    for i, a := range args {\n        if strings.HasPrefix(a, \"--\") && !strings.Contains(a, \"=\") {\n            name := strings.TrimPrefix(a, \"--\")\n            if isNonBoolFlag(flagSet, name) && i == len(args)-1 {\n                return fmt.Errorf(\"flag --%s is missing its value\", name)\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    var msg string\n    if fmt.Sprint(err) != \"\" && strings.HasPrefix(err.Error(), \"flag needs an argument: \") {\n        flagName := strings.TrimPrefix(err.Error(), \"flag needs an argument: \")\n        fmt.Fprintf(os.Stderr, \"supply a value: ... %s=<value>\\n\", flagName)\n        os.Exit(2)\n    }\n    _ = msg\n    return err\n}","preventionTips":["Quote shell variables: \"--config ${CFG:-default.toml}\" so empty vars never drop the token.","Prefer the --flag=value form; it fails only on a genuinely missing value.","Avoid building argv by string concatenation that can silently lose tokens.","Register toggles as bool flags so they never need values."],"tags":["cli","flag-parsing","missing-argument"],"backgroundTag":"flag-needs-argument","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}