JanDeDobbeleer/oh-my-posh · error

requires at least %d arg(s), only received %d

Error message

requires at least %d arg(s), only received %d

What it means

The command tree's MinimumNArgs(n) validator fires when a command receives fewer positional arguments than the required minimum. Unlike ExactArgs it allows extra arguments, but the minimum must be met. Commands with required inputs (like a shell name for `init`) use this to fail fast with a clear message.

Source

Thrown at src/cmdtree/cmdtree.go:505

	}

	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 {
		if len(args) < minimum || len(args) > maximum {
			return fmt.Errorf("accepts between %d and %d arg(s), received %d", minimum, maximum, len(args))
		}

		return nil
	}
}

func OnlyValidArgs(cmd *Command, args []string) error {
	if len(cmd.ValidArgs) == 0 {

View on GitHub (pinned to 0976794618)

Solutions

  1. Supply all required positional arguments shown in `oh-my-posh <command> --help`
  2. Quote arguments with spaces so they count as one arg rather than being split
  3. Update shell aliases/functions that call the command without forwarding "$@"

Example fix

// before
oh-my-posh init
// after
oh-my-posh init bash
Defensive patterns

Strategy: validation

Validate before calling

const minArgs = 1;
if ((process.argv.length - 2) < minArgs) {
  throw new Error(`command requires at least ${minArgs} positional argument(s)`);
}

Type guard

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

Try / catch

try {
  runCommand(args);
} catch (err) {
  if (err.message.includes('requires at least')) {
    printUsageAndExit();
  }
  throw err;
}

Prevention

When it happens

Trigger: Invoking a command registered with MinimumNArgs(n) with zero or fewer than n positional arguments, e.g. `oh-my-posh init` without specifying a shell.

Common situations: Omitting the mandatory shell name (`oh-my-posh init` instead of `oh-my-posh bash`), running an alias or wrapper script that drops arguments, or docs examples that assumed the shell argument.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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