ahmetb/kubectx · error

'%s' requires a context name argument (or fzf for interactiv

Error message

'%s' requires a context name argument (or fzf for interactive mode)

What it means

Argument-validation error returned via UnsupportedOp from parseArgs: the --readonly/-r flag was given with no target context name, and stdout is not an interactive terminal (so the fzf picker cannot be offered). The flag demands exactly one context argument in non-interactive mode.

Source

Thrown at cmd/kubectx/flags.go:48

	return op.Err
}

// parseArgs looks at flags (excl. executable name, i.e. argv[0])
// and decides which operation should be taken.
func parseArgs(argv []string) Op {
	if len(argv) == 0 {
		if cmdutil.IsInteractiveMode(os.Stdout) {
			return InteractiveSwitchOp{}
		}
		return ListOp{}
	}

	if argv[0] == "--readonly" || argv[0] == "-r" {
		if len(argv) == 1 {
			if cmdutil.IsInteractiveMode(os.Stdout) {
				return InteractiveReadonlyShellOp{}
			}
			return UnsupportedOp{Err: fmt.Errorf("'%s' requires a context name argument (or fzf for interactive mode)", argv[0])}
		}
		if len(argv) == 2 {
			return ReadonlyShellOp{Target: argv[1]}
		}
		return UnsupportedOp{Err: fmt.Errorf("'%s' accepts at most one context name argument", argv[0])}
	}

	if argv[0] == "--shell" || argv[0] == "-s" {
		if len(argv) == 1 {
			if cmdutil.IsInteractiveMode(os.Stdout) {
				return InteractiveShellOp{}
			}
			return UnsupportedOp{Err: fmt.Errorf("'%s' requires a context name argument (or fzf for interactive mode)", argv[0])}
		}
		if len(argv) == 2 {
			return ShellOp{Target: argv[1]}
		}
		return UnsupportedOp{Err: fmt.Errorf("'%s' accepts at most one context name argument", argv[0])}

View on GitHub (pinned to 12ad6fb22e)

Solutions

  1. Provide a context name: `kubectx --readonly <NAME>`
  2. Run from an interactive terminal to use the fzf picker with just `-r`
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cmd/kubectx/flags.go:48 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ahmetb/kubectx@12ad6fb22e (2026-09-02). Data as JSON: /api/errors/8ad3c36c66f2ef03. Report an issue: GitHub.