{"record":{"id":"9c2b5e9d87c4a7b6","repo":"urfave/cli","slug":"no-such-flag-s","errorCode":null,"errorMessage":"no such flag -%s","messagePattern":"no such flag -(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":539,"sourceCode":"func (cmd *Command) setMultiValueParsingConfig(f Flag) {\n\ttracef(\"setMultiValueParsingConfig %T, %+v\", f, f)\n\tif cf, ok := f.(multiValueParsingConfigSetter); ok {\n\t\tcf.setMultiValueParsingConfig(multiValueParsingConfig{\n\t\t\tSliceFlagSeparator:        cmd.SliceFlagSeparator,\n\t\t\tDisableSliceFlagSeparator: cmd.DisableSliceFlagSeparator,\n\t\t\tMapFlagKeyValueSeparator:  cmd.MapFlagKeyValueSeparator,\n\t\t})\n\t}\n}\n\n// Set sets a context flag to a value.\nfunc (cmd *Command) Set(name, value string) error {\n\tif f := cmd.lookupFlag(name); f != nil {\n\t\tcmd.setMultiValueParsingConfig(f)\n\t\treturn f.Set(name, value)\n\t}\n\n\treturn fmt.Errorf(\"no such flag -%s\", name)\n}\n\n// IsSet determines if the flag was actually set\nfunc (cmd *Command) IsSet(name string) bool {\n\tfl := cmd.lookupFlag(name)\n\tif fl == nil {\n\t\ttracef(\"flag with name %[1]q NOT found; assuming not set (cmd=%[2]q)\", name, cmd.Name)\n\t\treturn false\n\t}\n\n\tisSet := fl.IsSet()\n\tif isSet {\n\t\ttracef(\"flag with name %[1]q is set (cmd=%[2]q)\", name, cmd.Name)\n\t} else {\n\t\ttracef(\"flag with name %[1]q is no set (cmd=%[2]q)\", name, cmd.Name)\n\t}\n\n\treturn isSet","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/urfave/cli/blob/1a4deb4f5a35ee12706602698dc0527d44c14b19/command.go#L521-L557","documentation":"Command.Set looks up a registered flag by name on the command (and its persistent/parent flags). When no flag with that name exists, it returns 'no such flag -<name>' instead of silently ignoring the assignment. It is the programmatic equivalent of passing an undefined flag on the command line.","triggerScenarios":"Calling cmd.Set(name, value) with a name that was never registered via Flags (or aliases), a typo in the flag name, or referencing a flag defined only on a different (non-root/non-parent) command.","commonSituations":"Setting flags dynamically from config files or environment where key names are free-form; tests invoking Set on a subcommand while the flag is declared on the root; renaming a flag and forgetting to update Set call sites.","solutions":["Fix the flag name passed to Set, matching the declared Name or an alias exactly","Ensure the flag is declared in the Flags field of the command (or root/persistent flags) before Set is called","Use cmd.lookupFlag-equivalent checks like cmd.IsSet/cmd.Flag names first, or iterate cmd.Flags to verify existence"],"exampleFix":"// before\ncmd.Set(\"verbose\", \"true\") // flag declared as 'verbosity'\n// after\ncmd.Set(\"verbosity\", \"true\")","handlingStrategy":"validation","validationCode":"if cmd.LookupFlagName == nil { for _, f := range cmd.Flags { _ = f.Names() } }\n// preferred: probe before Set\nif err := cmd.Set(name, val); err != nil && strings.HasPrefix(err.Error(), \"no such flag\") { /* handle */ }","typeGuard":"func hasFlag(cmd *cli.Command, name string) bool {\n    for _, f := range cmd.Flags {\n        for _, n := range f.Names() {\n            if n == name { return true }\n        }\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Verify flag names against f.Names() output before calling Set","Keep flag name constants shared between declaration and Set call sites","Add a test that sets every configured flag key programmatically"],"tags":["go","cli","flags"],"backgroundTag":"unknown-flag","analyzedSha":"1a4deb4f5a35ee12706602698dc0527d44c14b19","analyzedAt":"2026-08-31T18:42:09.451Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}