{"record":{"id":"2468df6f39e04fe0","repo":"JanDeDobbeleer/oh-my-posh","slug":"unknown-flag-s","errorCode":null,"errorMessage":"unknown flag: --%s","messagePattern":"unknown flag: --(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdflag/cmdflag.go","lineNumber":280,"sourceCode":"\t}\n\n\treturn nil\n}\n\nfunc (f *FlagSet) parseLong(name string, rest []string) ([]string, error) {\n\tvalue := \"\"\n\thasValue := false\n\n\tif i := strings.Index(name, \"=\"); i >= 0 {\n\t\tvalue = name[i+1:]\n\t\tname = name[:i]\n\t\thasValue = true\n\t}\n\n\tflag := f.flags[name]\n\tif flag == nil {\n\t\tif !f.ParseErrorsAllowlist.UnknownFlags {\n\t\t\treturn rest, fmt.Errorf(\"unknown flag: --%s\", name)\n\t\t}\n\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:]","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdflag/cmdflag.go#L262-L298","documentation":"This is the cmdflag parser's 'unknown long flag' error. When Parse encounters a token starting with '--', parseLong strips the '--' and looks the name up in the FlagSet's registered flags. If no flag with that name was registered via Var/StringVar/BoolVar etc., and the FlagSet's ParseErrorsAllowlist.UnknownFlags is false (the default), parsing stops with this error.","triggerScenarios":"Calling FlagSet.Parse (directly or via cmdtree Command.execute) with a '--name' or '--name=value' token whose name was never registered on the FlagSet or inherited persistent flag sets, while ParseErrorsAllowlist.UnknownFlags is false.","commonSituations":"Users typing a misspelled flag (e.g. --config vs --conf); scripts carrying flags from an older CLI version that was renamed or removed; passing flags intended for a subcommand at the parent level; a plugin/script forwarding flags the command does not declare.","solutions":["Fix the typo in the flag name on the command line (run the command with --help to list valid flags).","Register the flag on the FlagSet with Var/StringVar/IntVar/etc. before calling Parse if it should exist.","Set f.ParseErrorsAllowlist.UnknownFlags = true to silently ignore unknown flags instead of erroring.","Check the CLI version: if a script uses a flag removed in a newer oh-my-posh, update the script or pin the old version."],"exampleFix":"// before\nerr := fs.Parse([]string{\"--verbos\", \"x\"}) // unknown flag: --verbos\n// after\nfs.BoolVarP(&verbose, \"verbose\", \"v\", false, \"verbose output\")\nerr := fs.Parse([]string{\"--verbose\", \"x\"})","handlingStrategy":"validation","validationCode":"func validateFlags(fs *cmdflag.FlagSet, args []string) error {\n    for _, a := range args {\n        if strings.HasPrefix(a, \"--\") {\n            name := strings.TrimPrefix(strings.SplitN(a[2:], \"=\", 2)[0], \"--\")\n            name = strings.SplitN(name, \"=\", 2)[0]\n            if fs.Lookup(name) == nil {\n                return fmt.Errorf(\"flag --%s is not registered; run with --help for valid flags\", name)\n            }\n        }\n    }\n    return nil\n}","typeGuard":"func isRegisteredFlag(fs *cmdflag.FlagSet, long string) bool {\n    return fs.Lookup(strings.TrimPrefix(long, \"--\")) != nil\n}","tryCatchPattern":"if err := fs.Parse(args); err != nil {\n    if strings.HasPrefix(err.Error(), \"unknown flag: \") {\n        fmt.Fprintln(os.Stderr, err, \"\\nRun with --help to see valid flags.\")\n        return errSilent // already reported; skip double handling\n    }\n    return err\n}","preventionTips":["Run the command with --help before scripting unfamiliar flags.","Enable ParseErrorsAllowlist.UnknownFlags only deliberately, and log ignored flags.","Add CI smoke tests that invoke your CLI with the exact flag sets your scripts use.","Prefer long flag names spelled out to reduce typos."],"tags":["cli","flag-parsing","cmdflag"],"backgroundTag":"unknown-flag","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}