wavetermdev/waveterm · error

requires a key argument

Error message

requires a key argument

What it means

Without --all, `wsh getvar` requires exactly one positional key naming the variable to read. When len(args) != 1, getVarRun prints the command help via OutputHelpMessage and returns this error (cmd/wshcmd-getvar.go:82). It enforces the command's argument contract before any RPC is made.

Source

Thrown at cmd/wsh/cmd/wshcmd-getvar.go:82

			blockArg = "client"
		}
	}
	fullORef, err := resolveBlockArg()
	if err != nil {
		return err
	}

	if getVarAllVars {
		if len(args) > 0 {
			return fmt.Errorf("cannot specify key with --all")
		}
		return getAllVariables(fullORef.OID)
	}

	// Single variable case - existing logic
	if len(args) != 1 {
		OutputHelpMessage(cmd)
		return fmt.Errorf("requires a key argument")
	}

	key := args[0]
	commandData := wshrpc.CommandVarData{
		Key:      key,
		ZoneId:   fullORef.OID,
		FileName: getVarFileName,
	}

	resp, err := wshclient.GetVarCommand(RpcClient, commandData, &wshrpc.RpcOpts{Timeout: 2000})
	if err != nil {
		return fmt.Errorf("getting variable: %w", err)
	}

	if !resp.Exists {
		WshExitCode = 1
		return nil
	}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Pass exactly one key: `wsh getvar FOO`
  2. Use `wsh getvar --all` if you want every variable instead of one
  3. Check the Read the docs output from OutputHelpMessage to confirm flag/value pairing (e.g. --varfile <name>)

Example fix

// before
wsh getvar
// after
wsh getvar FOO
Defensive patterns

Strategy: validation

Validate before calling

[ $# -eq 1 ] || { echo 'usage: wsh getvar <key>'; exit 2; }

Prevention

When it happens

Trigger: Running bare `wsh getvar`, or passing zero or multiple positional args such as `wsh getvar FOO BAR` without --all.

Common situations: Forgetting the key in a script after refactoring; accidentally passing flags that consume values (e.g. --varfile without a value) leaving no positional arg; shell splitting removing an empty quoted key.

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 wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/ea00ef74d87ee48a. Report an issue: GitHub.