JanDeDobbeleer/oh-my-posh · error

accepts %d arg(s), received %d

Error message

accepts %d arg(s), received %d

What it means

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).

Source

Thrown at src/cmdtree/cmdtree.go:495

	}

	return sb.String()
}

// positional argument validators

func NoArgs(cmd *Command, args []string) error {
	if len(args) > 0 {
		return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath())
	}

	return nil
}

func ExactArgs(n int) PositionalArgs {
	return func(_ *Command, args []string) error {
		if len(args) != n {
			return fmt.Errorf("accepts %d arg(s), received %d", n, len(args))
		}

		return nil
	}
}

func MinimumNArgs(n int) PositionalArgs {
	return func(_ *Command, args []string) error {
		if len(args) < n {
			return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args))
		}

		return nil
	}
}

func RangeArgs(minimum, maximum int) PositionalArgs {
	return func(_ *Command, args []string) error {

View on GitHub (pinned to 0976794618)

Solutions

  1. Count the positional arguments passed to the command and match the documented arity exactly
  2. Quote arguments containing spaces so the shell does not split them into multiple args
  3. Remove stray positional arguments; use flags (e.g. --config) instead of extra positionals
  4. Check `oh-my-posh <command> --help` for the exact expected usage

Example fix

// before
oh-my-posh config colorize extra-arg
// after
oh-my-posh config colorize
Defensive patterns

Strategy: validation

Validate before calling

const expected = 1; // arity documented for the command
if (process.argv.length - 2 !== expected) {
  throw new Error(`accepts ${expected} arg(s), received ${process.argv.length - 2}`);
}

Type guard

function hasExactArgs(args, n) { return Array.isArray(args) && args.length === n; }

Try / catch

try {
  runCommand(args);
} catch (err) {
  if (String(err.message).includes('accepts') && err.message.includes('arg(s)')) {
    printUsageAndExit();
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/c37ee864635b8e3e. Report an issue: GitHub.