wavetermdev/waveterm · error

wsh token requires exactly 2 arguments, got %d

Error message

wsh token requires exactly 2 arguments, got %d

What it means

`wsh token` requires exactly two arguments: the token string and the shell type. Cobra passes whatever the user typed, and tokenCmdRun enforces len(args) == 2, printing help and returning this error otherwise.

Source

Thrown at cmd/wsh/cmd/wshcmd-token.go:27

	"github.com/spf13/cobra"
	"github.com/wavetermdev/waveterm/pkg/util/shellutil"
)

var tokenCmd = &cobra.Command{
	Use:    "token [token] [shell-type]",
	Short:  "exchange token for shell initialization script",
	RunE:   tokenCmdRun,
	Hidden: true,
}

func init() {
	rootCmd.AddCommand(tokenCmd)
}

func tokenCmdRun(cmd *cobra.Command, args []string) (rtnErr error) {
	if len(args) != 2 {
		OutputHelpMessage(cmd)
		return fmt.Errorf("wsh token requires exactly 2 arguments, got %d", len(args))
	}
	tokenStr, shellType := args[0], args[1]
	if tokenStr == "" || shellType == "" {
		OutputHelpMessage(cmd)
		return fmt.Errorf("wsh token requires non-empty arguments")
	}
	rtnData, err := setupRpcClientWithToken(tokenStr)
	if err != nil {
		return fmt.Errorf("error setting up rpc client: %w", err)
	}
	envScriptText, err := shellutil.EncodeEnvVarsForShell(shellType, rtnData.Env)
	if err != nil {
		return fmt.Errorf("error encoding env vars: %w", err)
	}
	WriteStdout("%s\n", envScriptText)
	WriteStdout("%s\n", rtnData.InitScriptText)
	return nil
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Supply exactly two arguments: `wsh token <token> <shelltype>` (e.g. `wsh token abc123 bash`).
  2. Run `wsh token --help` to see the expected usage.
  3. Check shell quoting if arguments contain spaces or special characters.

Example fix

// before
wsh token mytoken
// after
wsh token mytoken bash
Defensive patterns

Strategy: validation

Validate before calling

# check argument count before invoking
if [ "$#" -ne 2 ]; then echo "usage: wsh token <token> <shelltype>"; exit 1; fi
wsh token "$@"

Try / catch

// in scripts, capture and branch on the error
if ! wsh token "$TOKEN" "$SHELLTYPE"; then
	echo "wsh token failed: expected exactly 2 arguments" >&2
	exit 1
fi

Prevention

When it happens

Trigger: Running `wsh token` with zero, one, or three-plus arguments — e.g. omitting the shell type, or quoting mistakes that split/merge arguments.

Common situations: Forgetting the second argument (token only); including an extra flag-like word; shell quoting collapsing or expanding arguments unexpectedly.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/0643899e3d2d272d. Report an issue: GitHub.