JanDeDobbeleer/oh-my-posh · error

invalid argument %q for "--%s" flag: %v

Error message

invalid argument %q for "--%s" flag: %v

What it means

Raised when the value supplied to a long flag fails flag.Value.Set. The parser found a value (via =, or the next token), but converting it failed - e.g. ParseBool rejecting 'yes' for a bool flag, or ParseInt rejecting 'abc' for an int flag. The original Set error is wrapped into the message with the value and flag name.

Source

Thrown at src/cmdflag/cmdflag.go:304

			return rest[1:], nil
		}

		return rest, nil
	}

	switch {
	case hasValue:
	case flag.Value.Type() == boolType:
		value = trueStr
	case len(rest) > 0:
		value = rest[0]
		rest = rest[1:]
	default:
		return rest, fmt.Errorf("flag needs an argument: --%s", name)
	}

	if err := flag.Value.Set(value); err != nil {
		return rest, fmt.Errorf("invalid argument %q for \"--%s\" flag: %v", value, flag.Name, err)
	}

	flag.Changed = true
	return rest, nil
}

func (f *FlagSet) parseShort(shorthands string, rest []string) ([]string, error) {
	for len(shorthands) > 0 {
		c := shorthands[0]

		flag := f.shorthands[c]
		if flag == nil {
			if f.ParseErrorsAllowlist.UnknownFlags {
				// drop the remainder of the group and a
				// separate value token unless it is itself a flag
				if len(shorthands) == 1 && len(rest) > 0 && !strings.HasPrefix(rest[0], "-") {
					return rest[1:], nil
				}

View on GitHub (pinned to 0976794618)

Solutions

  1. Supply a value parseable for the flag's type: true/false/1/0 for bools, plain integers for int, numeric for float.
  2. Read the wrapped %v error at the end of the message - it names the exact parse failure from strconv.
  3. Fix shell quoting so stray characters or empty strings don't reach the parser.
  4. Change the flag's Value implementation to accept the input format if you control the CLI (custom Value type with tolerant Set).

Example fix

// before
omp args: "--debug=yes" -> invalid argument "yes" for "--debug" flag: strconv.ParseBool: parsing "yes": invalid syntax
// after
args := []string{"--debug=true"} // or just "--debug"
Defensive patterns

Strategy: validation

Validate before calling

func validateFlagValue(typ, val string) error {
    switch typ {
    case "bool":
        if _, err := strconv.ParseBool(val); err != nil {
            return fmt.Errorf("%q is not a valid bool (use true/false/1/0)", val)
        }
    case "int":
        if _, err := strconv.ParseInt(val, 0, 64); err != nil {
            return fmt.Errorf("%q is not a valid integer", val)
        }
    case "float64":
        if _, err := strconv.ParseFloat(val, 64); err != nil {
            return fmt.Errorf("%q is not a valid float", val)
        }
    }
    return nil
}

Try / catch

if err := cmd.Execute(); err != nil {
    if i := strings.Index(err.Error(), "invalid argument "); i == 0 {
        // message already contains value, flag, and the strconv cause
        fmt.Fprintf(os.Stderr, "%v\nRun with --help for accepted formats.\n", err)
        os.Exit(2)
    }
    return err
}

Prevention

When it happens

Trigger: Parse called with '--flag=value' where value is invalid for the flag's registered type (boolValue, intValue, float64Value): e.g. '--debug=1x' for a bool, '--threads=ten' for an int.

Common situations: Users passing Go-unfriendly bool spellings (yes/no/on/off instead of true/false/1/0); copy-pasting values with units ('4s' into an int flag); locale-formatted numbers with commas; scripts interpolating empty strings ('--port=' with int parse error).

Related errors


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