{"record":{"id":"a7020f5660faa7c5","repo":"JanDeDobbeleer/oh-my-posh","slug":"no-such-flag-v","errorCode":null,"errorMessage":"no such flag -%v","messagePattern":"no such flag -(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdtree/cmdtree.go","lineNumber":132,"sourceCode":"\nfunc (c *Command) PersistentFlags() *cmdflag.FlagSet {\n\tif c.pflags == nil {\n\t\tc.pflags = cmdflag.NewFlagSet(c.Name(), cmdflag.ContinueOnError)\n\t}\n\n\treturn c.pflags\n}\n\nfunc (c *Command) SetArgs(args []string) {\n\tc.setArgs = args\n}\n\n// MarkPersistentFlagRequired only applies to a flag registered on this\n// command's own persistent set and errors otherwise.\nfunc (c *Command) MarkPersistentFlagRequired(name string) error {\n\tflag := c.PersistentFlags().Lookup(name)\n\tif flag == nil {\n\t\treturn fmt.Errorf(\"no such flag -%v\", name)\n\t}\n\n\tc.requiredFlags = append(c.requiredFlags, name)\n\treturn nil\n}\n\nfunc (c *Command) hasSubCommands() bool {\n\tfor _, cmd := range c.commands {\n\t\tif !cmd.Hidden && cmd.Name() != \"help\" {\n\t\t\treturn true\n\t\t}\n\t}\n\n\treturn false\n}\n\nfunc (c *Command) findChild(name string) *Command {\n\tfor _, cmd := range c.commands {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdtree/cmdtree.go#L114-L150","documentation":"MarkPersistentFlagRequired can only mark flags registered on the command's own PersistentFlags set. It looks the name up in PersistentFlags() and returns this error when the flag is not found there - typically because it was registered as a local flag (Flags()), on a different command, or never registered at all. No state is changed when this happens.","triggerScenarios":"Calling cmd.MarkPersistentFlagRequired(\"name\") where cmd.PersistentFlags().Lookup(\"name\") returns nil - e.g. the flag was declared with cmd.Flags().StringVar(...) instead of cmd.PersistentFlags().StringVar(...), or a typo in the name.","commonSituations":"Copy-pasted cobra-style setup code where the flag was added as a local flag; marking a child's flag required from the parent command; renaming a flag in one place but not in the Mark... call; forgetting registration entirely before marking required.","solutions":["Register the flag on the command's persistent set first: cmd.PersistentFlags().StringVar(...) before MarkPersistentFlagRequired.","Verify the exact flag name matches the registered name (watch for typos).","If the flag is meant to be local-only, add a check in Run or use the requiredFlags mechanism appropriate to local flags instead.","Check you are calling the method on the command that owns the flag, not a parent or child."],"exampleFix":"// before\ncmd.Flags().Bool(\"upgrade\", false, \"upgrade\")\nerr := cmd.MarkPersistentFlagRequired(\"upgrade\") // no such flag -upgrade\n// after\ncmd.PersistentFlags().BoolVar(&upgrade, \"upgrade\", false, \"upgrade\")\nerr := cmd.MarkPersistentFlagRequired(\"upgrade\") // nil","handlingStrategy":"try-catch","validationCode":"func requirePersistent(cmd *cmdtree.Command, names ...string) error {\n    for _, n := range names {\n        if cmd.PersistentFlags().Lookup(n) == nil {\n            return fmt.Errorf(\"flag %q must be registered via PersistentFlags before MarkPersistentFlagRequired\", n)\n        }\n    }\n    return nil\n}","typeGuard":"func hasPersistentFlag(cmd *cmdtree.Command, name string) bool {\n    return cmd.PersistentFlags().Lookup(name) != nil\n}","tryCatchPattern":"if err := cmd.MarkPersistentFlagRequired(\"config\"); err != nil {\n    // \"no such flag -config\": registration order or ownership problem\n    panic(fmt.Sprintf(\"CLI setup bug: %v\", err)) // fail fast at startup, not at runtime\n}","preventionTips":["Always register on PersistentFlags() before calling MarkPersistentFlagRequired.","Call Mark... on the command that owns the flag, never on a parent/child.","Grep for both the registration and the Mark call when renaming flags to keep names in sync.","Check the returned error at startup - it signals a wiring bug, not user input."],"tags":["cli","cmdtree","developer-error","flag-registration"],"backgroundTag":"flag-not-registered","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}