JanDeDobbeleer/oh-my-posh · error

flag %q does not exist

Error message

flag %q does not exist

What it means

FlagSet.MarkHidden looks up a flag by name in the set's internal map and marks it hidden from help output. If no flag with that name is registered, it returns this error quoting the requested name. It is a programmatic lookup failure, not a runtime user error.

Source

Thrown at src/cmdflag/cmdflag.go:182

}

func (f *FlagSet) ShorthandLookup(name string) *Flag {
	if name == "" {
		return nil
	}

	return f.shorthands[name[0]]
}

func (f *FlagSet) Changed(name string) bool {
	flag := f.flags[name]
	return flag != nil && flag.Changed
}

func (f *FlagSet) MarkHidden(name string) error {
	flag := f.flags[name]
	if flag == nil {
		return fmt.Errorf("flag %q does not exist", name)
	}

	flag.Hidden = true
	return nil
}

// VisitAll visits the flags in registration order rather than
// lexicographically: the sole caller formats a command line and is
// order-insensitive, and usage rendering sorts separately.
func (f *FlagSet) VisitAll(fn func(*Flag)) {
	for _, flag := range f.order {
		fn(flag)
	}
}

// AddFlagSet adds flags from another set that are not yet present.
func (f *FlagSet) AddFlagSet(other *FlagSet) {
	if other == nil {

View on GitHub (pinned to 0976794618)

Solutions

  1. Fix the name passed to MarkHidden to match the registered flag exactly
  2. Ensure the flag is added (AddFlag/definition) before MarkHidden is called
  3. Call MarkHidden on the FlagSet/command that actually owns the flag

Example fix

// before
flags.MarkHidden("verboose")
// after
flags.MarkHidden("verbose")
Defensive patterns

Strategy: validation

Validate before calling

if flags.Lookup(name) == nil {
    return fmt.Errorf("flag %q does not exist", name) // or skip hiding
}
return flags.MarkHidden(name)

Try / catch

if err := flags.MarkHidden("verbose"); err != nil {
    // flag name typo or wrong FlagSet: fix the call, don't ignore at runtime
}

Prevention

When it happens

Trigger: Calling MarkHidden(name) with a flag name that was never added via the FlagSet (typo, wrong casing, or the flag is registered on a different FlagSet/command).

Common situations: Renaming a flag but forgetting to update the MarkHidden call; attempting to hide an inherited/parent command's flag from a subcommand's FlagSet.

Related errors


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