{"record":{"id":"5d1654882c3eda24","repo":"JanDeDobbeleer/oh-my-posh","slug":"unknown-shorthand-flag-q-in-s","errorCode":null,"errorMessage":"unknown shorthand flag: %q in -%s","messagePattern":"unknown shorthand flag: %q in -(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdflag/cmdflag.go","lineNumber":327,"sourceCode":"}\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}\n\n\t\t\t\treturn rest, nil\n\t\t\t}\n\n\t\t\treturn rest, fmt.Errorf(\"unknown shorthand flag: %q in -%s\", c, shorthands)\n\t\t}\n\n\t\tvalue := \"\"\n\n\t\tswitch {\n\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 = \"\"","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdflag/cmdflag.go#L309-L345","documentation":"parseShort walks each character of a '-abc' shorthand group and looks each one up in the FlagSet's shorthand map. If a character has no registered shorthand and ParseErrorsAllowlist.UnknownFlags is false, the parser stops with this error naming the offending character and the remaining group.","triggerScenarios":"Parse called with a '-x...' token where character x (or any later character in the cluster) was never registered via a *VarP shorthand parameter, and UnknownFlags allowlisting is off.","commonSituations":"Muscle-memory from other CLIs (-v meaning something else here, or being long-only); scripts combining shorthands that don't exist; typos like -V vs -v; users of the old cobra/flag-based CLI using shorthands that were dropped in a rewrite.","solutions":["Use the correct registered shorthand (check the command's help output under Flags).","Spell the flag in long form (--name) which is often easier to get right.","Register the shorthand via StringVarP/BoolVarP/etc. if you control the CLI.","Set ParseErrorsAllowlist.UnknownFlags = true to ignore unknown shorthand groups instead of failing."],"exampleFix":"// before\nargs := []string{\"-z\"} // unknown shorthand flag: 'z' in -z\n// after\nargs := []string{\"--config\", \"file\"} // or register: fs.StringVarP(&cfg, \"config\", \"c\", \"\", \"config file\")","handlingStrategy":"validation","validationCode":"func validateShorthands(fs *cmdflag.FlagSet, args []string) error {\n    for _, a := range args {\n        if len(a) > 1 && a[0] == '-' && a[1] != '-' {\n            for _, c := range a[1:] {\n                ch := string(c)\n                if ch != \"=\" && fs.ShorthandLookup(ch) == nil {\n                    return fmt.Errorf(\"shorthand -%s is not registered\", ch)\n                }\n            }\n        }\n    }\n    return nil\n}","typeGuard":"func hasShorthand(fs *cmdflag.FlagSet, short string) bool {\n    return fs.ShorthandLookup(short) != nil\n}","tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if strings.HasPrefix(err.Error(), \"unknown shorthand flag:\") {\n        fmt.Fprintf(os.Stderr, \"%v\\nTip: use the long form (--name) or check -h.\\n\", err)\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Check the Flags section of --help for exact shorthand letters before scripting.","Prefer long flags in scripts; they are self-documenting and typo-resistant.","Re-verify shorthands after CLI upgrades - they can change between versions.","Note shorthands are single characters; combining them in clusters requires each to be registered."],"tags":["cli","flag-parsing","shorthand"],"backgroundTag":"unknown-flag","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}