ahmetb/kubectx · warning

unsupported arguments %q

Error message

unsupported arguments %q

What it means

parseArgs validates kubens command-line arguments for the rename/force forms. When the arguments neither match "{namespace} -f|--force" nor "-f|--force {namespace}" (nor a plain namespace switch), it returns UnsupportedOp with "unsupported arguments %q" listing the raw argv. This is a usage error, not a runtime failure.

Source

Thrown at cmd/kubens/flags.go:67

		case "--help", "-h":
			return HelpOp{}
		case "--version", "-V":
			return VersionOp{}
		case "--current", "-c":
			return CurrentOp{}
		case "--unset", "-u":
			return UnsetOp{}
		default:
			return getSwitchOp(v, false)
		}
	} else if n == 2 {
		// {namespace} -f|--force
		name := argv[0]
		force := slices.Contains([]string{"-f", "--force"}, argv[1])

		if !force {
			if !slices.Contains([]string{"-f", "--force"}, argv[0]) {
				return UnsupportedOp{Err: fmt.Errorf("unsupported arguments %q", argv)}
			}

			// -f|--force {namespace}
			force = true
			name = argv[1]
		}

		return getSwitchOp(name, force)
	}

	return UnsupportedOp{Err: fmt.Errorf("too many arguments")}
}

func getSwitchOp(v string, force bool) Op {
	if strings.HasPrefix(v, "-") && v != "-" {
		return UnsupportedOp{Err: fmt.Errorf("unsupported option %q", v)}
	}
	return SwitchOp{Target: v, Force: force}

View on GitHub (pinned to 12ad6fb22e)

Solutions

  1. Use the documented forms: `kubens <namespace>` or `kubens -f <namespace>` (or `kubens <namespace> -f`)
  2. Run `kubens --help` to see accepted argument shapes
  3. Quote the namespace name to prevent the shell from splitting it into multiple args
  4. Remove unintended extra arguments from scripts calling kubens

Example fix

// before
kubens foo bar
// after
kubens foo            # plain switch
kubens -f foo         # force switch
Defensive patterns

Strategy: validation

Validate before calling

args := os.Args[1:]
valid := len(args) == 1 ||
    (len(args) == 2 && (args[0] == "-f" || args[0] == "--force" || args[1] == "-f" || args[1] == "--force"))
if !valid {
    return fmt.Errorf("usage: kubens [-f] <namespace>")
}

Try / catch

op := kubens.ParseArgs(argv)
if uo, ok := op.(kubens.UnsupportedOp); ok {
    fmt.Fprintf(stderr, "usage error: %v\n", uo.Err)
    os.Exit(2) // usage error, not runtime failure
}

Prevention

When it happens

Trigger: Calling kubens with two arguments where neither is -f/--force, e.g. `kubens foo bar`, or a single stray flag like `kubens -x`.

Common situations: Typos in the namespace name combined with flags; users guessing at flag syntax; shell scripts passing extra positional arguments; confusing kubens flags with kubectl's.

Related errors


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