{"record":{"id":"7cff62d60b2295dc","repo":"charmbracelet/crush","slug":"s-s-requires-a-value","errorCode":null,"errorMessage":"%s: --%s requires a value","messagePattern":"(.+?): --(.+?) requires a value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/shellconfig/flags.go","lineNumber":185,"sourceCode":"\t\tv, err := nextArg(args, i, name)\n\t\tif err != nil {\n\t\t\treturn nil, 0, err\n\t\t}\n\t\tvar parsed any\n\t\tif err := json.Unmarshal([]byte(v), &parsed); err != nil {\n\t\t\treturn nil, 0, fmt.Errorf(\"%s: --%s expects valid JSON, got %q: %s\", args[0], name, v, err)\n\t\t}\n\t\treturn parsed, i + 2, nil\n\n\tdefault:\n\t\treturn nil, 0, fmt.Errorf(\"%s: --%s has unknown flag kind\", args[0], name)\n\t}\n}\n\n// nextArg returns args[i+1], erroring if the flag is missing its value.\nfunc nextArg(args []string, i int, flag string) (string, error) {\n\tif i+1 >= len(args) {\n\t\treturn \"\", fmt.Errorf(\"%s: --%s requires a value\", args[0], flag)\n\t}\n\treturn args[i+1], nil\n}\n\n// storeFlag writes a parsed value into target according to spec.op.\nfunc storeFlag(target map[string]any, spec flagSpec, val any) {\n\tswitch spec.op {\n\tcase opSet:\n\t\ttarget[spec.jsonKey] = val\n\tcase opAppend:\n\t\tarr, _ := target[spec.jsonKey].([]any)\n\t\ttarget[spec.jsonKey] = append(arr, val)\n\tcase opSetChild:\n\t\tif kv, ok := val.([2]string); ok {\n\t\t\tchildMap(target, spec.child)[kv[0]] = kv[1]\n\t\t}\n\tcase opMergeChild:\n\t\tif obj, ok := val.(map[string]any); ok {","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/shellconfig/flags.go#L167-L203","documentation":"This error is thrown by nextArg, the shared helper that fetches args[i+1] for value-taking flags (flagString, flagBool, flagInt, flagFloat, flagJSONObject, flagJSONAny). It fires when a flag that requires exactly one value is the last token on the command line, so no value argument exists. nextArg is called from parseFlagValue, which propagates it up through applyFlags as a usage error.","triggerScenarios":"Ending a command with a value flag: `provider add x --api-key` (nothing after), or `--model` as the final token; also when shell expansion yields an empty trailing arg that is dropped, e.g. `--api-key $KEY` with KEY unset.","commonSituations":"Truncating a copied command and dropping the secret/token; unset environment variables expanding to nothing before the flag value; accidentally ordering a value flag last before pressing enter; copy-paste losing the value after a newline.","solutions":["Append the missing value: `--api-key <value>` must always be followed by exactly one token.","Quote the value: `--api-key \"$MY_KEY\"` and verify MY_KEY is set (`echo ${MY_KEY:?unset}`).","Use ${VAR:?} expansions so the shell aborts instead of silently dropping empty values.","Check the builtin's usage output to confirm which flags take values versus valueless booleans (e.g. --think takes none)."],"exampleFix":"// before\nprovider add anthropic --api-key\n// after\nprovider add anthropic --api-key \"$ANTHROPIC_API_KEY\"","handlingStrategy":"validation","validationCode":"# Ensure the flag is not the last token and its value is non-empty\n: \"${API_KEY:?API_KEY is unset}\"   # shell-level guard\n[ -n \"$API_KEY\" ] || exit 2","typeGuard":"func hasNextArg(args []string, i int) bool { return i+1 < len(args) }","tryCatchPattern":"if err := applyFlags(specs, args, start, target, cmd, stderr); err != nil {\n    if strings.Contains(err.Error(), \"requires a value\") {\n        fmt.Fprintln(stderr, \"That flag needs a value: --flag VALUE\")\n    }\n    return err\n}","preventionTips":["Never end a command on a value-taking flag; always follow it with a token.","Use ${VAR:?message} expansions so unset variables abort instead of vanishing.","Quote expansions (\"$KEY\") so embedded whitespace does not split into extra tokens.","Distinguish valueless boolean flags (e.g. --think) from value flags via the builtin's usage output."],"tags":["cli","argument-parsing","shell-config","missing-argument"],"backgroundTag":"missing-flag-value","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}