{"record":{"id":"ea00ef74d87ee48a","repo":"wavetermdev/waveterm","slug":"requires-a-key-argument","errorCode":null,"errorMessage":"requires a key argument","messagePattern":"requires a key argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-getvar.go","lineNumber":82,"sourceCode":"\t\t\tblockArg = \"client\"\n\t\t}\n\t}\n\tfullORef, err := resolveBlockArg()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif getVarAllVars {\n\t\tif len(args) > 0 {\n\t\t\treturn fmt.Errorf(\"cannot specify key with --all\")\n\t\t}\n\t\treturn getAllVariables(fullORef.OID)\n\t}\n\n\t// Single variable case - existing logic\n\tif len(args) != 1 {\n\t\tOutputHelpMessage(cmd)\n\t\treturn fmt.Errorf(\"requires a key argument\")\n\t}\n\n\tkey := args[0]\n\tcommandData := wshrpc.CommandVarData{\n\t\tKey:      key,\n\t\tZoneId:   fullORef.OID,\n\t\tFileName: getVarFileName,\n\t}\n\n\tresp, err := wshclient.GetVarCommand(RpcClient, commandData, &wshrpc.RpcOpts{Timeout: 2000})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting variable: %w\", err)\n\t}\n\n\tif !resp.Exists {\n\t\tWshExitCode = 1\n\t\treturn nil\n\t}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-getvar.go#L64-L100","documentation":"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.","triggerScenarios":"Running bare `wsh getvar`, or passing zero or multiple positional args such as `wsh getvar FOO BAR` without --all.","commonSituations":"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.","solutions":["Pass exactly one key: `wsh getvar FOO`","Use `wsh getvar --all` if you want every variable instead of one","Check the Read the docs output from OutputHelpMessage to confirm flag/value pairing (e.g. --varfile <name>)"],"exampleFix":"// before\nwsh getvar\n// after\nwsh getvar FOO","handlingStrategy":"validation","validationCode":"[ $# -eq 1 ] || { echo 'usage: wsh getvar <key>'; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply exactly one key unless using --all","Beware flags that swallow values (e.g. --varfile needs a value) leaving no positional arg","Quote the key to prevent shell splitting into multiple args"],"tags":["cli","usage","wsh"],"backgroundTag":"missing-required-argument","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}