{"record":{"id":"2d063181e69fd30e","repo":"JanDeDobbeleer/oh-my-posh","slug":"accepts-between-d-and-d-arg-s-received-d","errorCode":null,"errorMessage":"accepts between %d and %d arg(s), received %d","messagePattern":"accepts between (.+?) and (.+?) arg\\(s\\), received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdtree/cmdtree.go","lineNumber":515,"sourceCode":"\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 {\n\t\tif len(args) < minimum || len(args) > maximum {\n\t\t\treturn fmt.Errorf(\"accepts between %d and %d arg(s), received %d\", minimum, maximum, len(args))\n\t\t}\n\n\t\treturn nil\n\t}\n}\n\nfunc OnlyValidArgs(cmd *Command, args []string) error {\n\tif len(cmd.ValidArgs) == 0 {\n\t\treturn nil\n\t}\n\n\tfor _, arg := range args {\n\t\tif !contains(cmd.ValidArgs, arg) {\n\t\t\treturn fmt.Errorf(\"invalid argument %q for %q\", arg, cmd.CommandPath())\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdtree/cmdtree.go#L497-L533","documentation":"RangeArgs(minimum, maximum) validates that positional argument count falls within an inclusive range. This error is returned when len(args) is below minimum or above maximum. It gives commands flexibility (0..1 args, 1..2 args) while still bounding accepted input.","triggerScenarios":"Calling a command registered with RangeArgs(min, max) with an argument count outside the inclusive range, e.g. passing three positionals to a command that accepts between one and two.","commonSituations":"Pasting multi-word strings without quotes so one logical argument becomes several positional args, or appending extra tokens like a theme name where none is accepted.","solutions":["Check the command's documented arg range via --help and adjust the count","Quote multi-word arguments so they count as a single positional","Move optional extras into flags instead of positional arguments"],"exampleFix":"// before\noh-my-posh get shell extra1 extra2\n// after\noh-my-posh get shell","handlingStrategy":"validation","validationCode":"const min = 1, max = 2;\nconst n = process.argv.length - 2;\nif (n < min || n > max) {\n  throw new Error(`accepts between ${min} and ${max} arg(s), received ${n}`);\n}","typeGuard":"function hasArgRange(args, min, max) { return Array.isArray(args) && args.length >= min && args.length <= max; }","tryCatchPattern":"try {\n  runCommand(args);\n} catch (err) {\n  if (err.message.includes('accepts between')) {\n    printUsageAndExit();\n  }\n  throw err;\n}","preventionTips":["Quote multi-word arguments to keep the count correct","Consult --help for the accepted range","Replace optional extras with flags"],"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"}