{"record":{"id":"7235686784bf3392","repo":"urfave/cli","slug":"flag-needs-an-argument-s","errorCode":null,"errorMessage":"flag needs an argument: %s","messagePattern":"flag needs an argument: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command_parse.go","lineNumber":180,"sourceCode":"\t\t\t\t}\n\t\t\t\ttracef(\"parse Apply bool flag (fName=%[1]q) (fVal=%[2]q)\", flagName, flagVal)\n\t\t\t\tif err := cmd.set(flagName, f, flagVal); err != nil {\n\t\t\t\t\treturn &stringSliceArgs{posArgs}, err\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\ttracef(\"processing non bool flag (fName=%[1]q)\", flagName)\n\t\t\t// not a bool flag so need to get the next arg\n\t\t\tif flagVal == \"\" && !valFromEqual {\n\t\t\t\tif len(rargs) == 1 {\n\t\t\t\t\t// In shell completion mode, preserve the flag so that DefaultCompleteWithFlags can use it\n\t\t\t\t\t// as lastArg and offer suggestions for it.\n\t\t\t\t\tif cmd.Root().shellCompletion {\n\t\t\t\t\t\tposArgs = append(posArgs, rargs...)\n\t\t\t\t\t\treturn &stringSliceArgs{posArgs}, nil\n\t\t\t\t\t}\n\t\t\t\t\treturn &stringSliceArgs{posArgs}, fmt.Errorf(\"%s%s\", argumentNotProvidedErrMsg, firstArg)\n\t\t\t\t}\n\t\t\t\tflagVal = rargs[1]\n\t\t\t\trargs = rargs[1:]\n\t\t\t}\n\n\t\t\ttracef(\"setting non bool flag (fName=%[1]q) (fVal=%[2]q)\", flagName, flagVal)\n\t\t\tif err := cmd.set(flagName, f, flagVal); err != nil {\n\t\t\t\treturn &stringSliceArgs{posArgs}, err\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\n\t\t// no flag lookup found and short handling is disabled\n\t\tif !shortOptionHandling {\n\t\t\t// In shell completion mode, preserve the partial flag so that DefaultCompleteWithFlags can use it\n\t\t\t// as lastArg and offer suggestions that match the prefix.\n\t\t\tif cmd.Root().shellCompletion {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/urfave/cli/blob/1a4deb4f5a35ee12706602698dc0527d44c14b19/command_parse.go#L162-L198","documentation":"During parseFlags, a non-boolean flag was the last token on the command line (or consumed its only remaining arg), so no value was available to assign. The parser raises 'flag needs an argument: <name>'.","triggerScenarios":"Running a command where a value-taking flag appears last with no value, e.g. 'mycmd --output' or 'mycmd --config' with nothing after it; also when shell completion mode is off and the flag's value is missing.","commonSituations":"Shell scripts truncating trailing arguments; users forgetting a value after '=' style expectations; empty env-var expansion leaving '--flag ' with nothing following (e.g. mycmd --config $EMPTY).","solutions":["Pass a value with the flag: --config=app.yml or --config app.yml","Check scripts for empty variable expansions that swallow the flag's argument","If the flag should work without a value, change it to a bool flag (BoolFlag) or give it a default via Destination/Value"],"exampleFix":"// before\n$ app --config\n// after\n$ app --config=config.yml","handlingStrategy":"validation","validationCode":"args := os.Args[1:]\nfor i, a := range args {\n    if strings.HasPrefix(a, \"--\") && !strings.Contains(a, \"=\") && i == len(args)-1 {\n        // flag with no trailing value\n        fmt.Printf(\"flag %s requires a value\\n\", a)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(os.Args); err != nil {\n    if strings.Contains(err.Error(), \"flag needs an argument\") {\n        fmt.Fprintln(os.Stderr, \"usage: app --config <path>\")\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Use --flag=value syntax in scripts to make values explicit","Quote variables so empty expansions still bind a value: \"${CONFIG:-default}\"","Give value flags defaults so omission is safe"],"tags":["go","cli","flags","argument-parsing"],"backgroundTag":"flag-needs-argument","analyzedSha":"1a4deb4f5a35ee12706602698dc0527d44c14b19","analyzedAt":"2026-08-31T18:42:09.451Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}