{"record":{"id":"c37ee864635b8e3e","repo":"JanDeDobbeleer/oh-my-posh","slug":"accepts-d-arg-s-received-d","errorCode":null,"errorMessage":"accepts %d arg(s), received %d","messagePattern":"accepts (.+?) arg\\(s\\), received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdtree/cmdtree.go","lineNumber":495,"sourceCode":"\t}\n\n\treturn sb.String()\n}\n\n// positional argument validators\n\nfunc NoArgs(cmd *Command, args []string) error {\n\tif len(args) > 0 {\n\t\treturn fmt.Errorf(\"unknown command %q for %q\", args[0], cmd.CommandPath())\n\t}\n\n\treturn nil\n}\n\nfunc ExactArgs(n int) PositionalArgs {\n\treturn func(_ *Command, args []string) error {\n\t\tif len(args) != n {\n\t\t\treturn fmt.Errorf(\"accepts %d arg(s), received %d\", n, len(args))\n\t\t}\n\n\t\treturn nil\n\t}\n}\n\nfunc MinimumNArgs(n int) PositionalArgs {\n\treturn func(_ *Command, args []string) error {\n\t\tif len(args) < n {\n\t\t\treturn fmt.Errorf(\"requires at least %d arg(s), only received %d\", n, len(args))\n\t\t}\n\n\t\treturn nil\n\t}\n}\n\nfunc RangeArgs(minimum, maximum int) PositionalArgs {\n\treturn func(_ *Command, args []string) error {","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdtree/cmdtree.go#L477-L513","documentation":"oh-my-posh's internal cobra-like command tree rejects a command invocation when the number of positional arguments does not exactly match the count configured via ExactArgs(n). The validator compares len(args) against n and returns this formatted error when they differ. It exists to enforce strict arity on commands that require a fixed number of inputs (e.g. exactly one theme name).","triggerScenarios":"Calling a CLI command defined with ExactArgs(n) while passing fewer or more than n positional arguments, e.g. `oh-my-posh print primary extra` on a command that expects exactly one arg, or omitting the required theme/config argument entirely.","commonSituations":"Users copy a command from docs and add extra flags-as-positionals, shell word splitting accidentally creates extra args (unquoted paths with spaces), or a newer CLI version changed the expected argument count and an old script still runs.","solutions":["Count the positional arguments passed to the command and match the documented arity exactly","Quote arguments containing spaces so the shell does not split them into multiple args","Remove stray positional arguments; use flags (e.g. --config) instead of extra positionals","Check `oh-my-posh <command> --help` for the exact expected usage"],"exampleFix":"// before\noh-my-posh config colorize extra-arg\n// after\noh-my-posh config colorize","handlingStrategy":"validation","validationCode":"const expected = 1; // arity documented for the command\nif (process.argv.length - 2 !== expected) {\n  throw new Error(`accepts ${expected} arg(s), received ${process.argv.length - 2}`);\n}","typeGuard":"function hasExactArgs(args, n) { return Array.isArray(args) && args.length === n; }","tryCatchPattern":"try {\n  runCommand(args);\n} catch (err) {\n  if (String(err.message).includes('accepts') && err.message.includes('arg(s)')) {\n    printUsageAndExit();\n  }\n  throw err;\n}","preventionTips":["Always check --help for expected positional arity","Quote arguments containing spaces","Prefer flags over extra positionals in scripts","Use \"$@\" in shell wrappers to forward args unchanged"],"tags":["cli","arguments","arity"],"backgroundTag":"wrong-number-of-arguments","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}