{"record":{"id":"e6ba903814c34a94","repo":"JanDeDobbeleer/oh-my-posh","slug":"required-flag-s-s-not-set","errorCode":null,"errorMessage":"required flag(s) \"%s\" not set","messagePattern":"required flag\\(s\\) \"(.+?)\" not set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmdtree/cmdtree.go","lineNumber":323,"sourceCode":"\n\treturn result\n}\n\nfunc (c *Command) execute(args []string) error {\n\tc.registerHelpFlag()\n\tflags := c.mergedFlags()\n\n\tif err := flags.Parse(args); err != nil {\n\t\treturn c.flagError(err)\n\t}\n\n\tif c.helpRequested {\n\t\treturn c.Help()\n\t}\n\n\tfor _, name := range c.requiredFlags {\n\t\tif !flags.Changed(name) {\n\t\t\treturn c.flagError(fmt.Errorf(\"required flag(s) \\\"%s\\\" not set\", name))\n\t\t}\n\t}\n\n\tpositionals := flags.Args()\n\n\tif c.Args != nil {\n\t\tif err := c.Args(c, positionals); err != nil {\n\t\t\treturn c.flagError(err)\n\t\t}\n\t}\n\n\tif c.Run == nil {\n\t\treturn c.Help()\n\t}\n\n\tif hook := c.findHook(func(cmd *Command) func(*Command, []string) { return cmd.PersistentPreRun }); hook != nil {\n\t\thook(c, positionals)\n\t}","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cmdtree/cmdtree.go#L305-L341","documentation":"After parsing flags, Command.execute iterates the names collected by MarkPersistentFlagRequired and verifies each is Changed on the merged flag set. If a required persistent flag was not supplied on the command line, execution stops with this error, routed through flagError so usage is printed. Defaults do not count - only an explicit Set marks Changed.","triggerScenarios":"Executing a command that had MarkPersistentFlagRequired(name) called, without passing --name (or -short) on the command line, even if the flag has a non-empty default value.","commonSituations":"Scripts omitting a flag that a newer version made mandatory; users unaware a flag became required after an upgrade; env-var-driven invocations that relied on the default; help output missed because the error prints after parse succeeds.","solutions":["Pass the required flag explicitly: command --flag value on every invocation.","Wrap the flag with a default at registration if it should not be required - then remove the MarkPersistentFlagRequired call.","In scripts, source a default (e.g. ${CFG:-default.toml}) so the flag is always supplied.","Check release notes after upgrading the CLI: required flags may have changed."],"exampleFix":"// before\nargs := []string{\"shell\"} // required flag(s) \"config\" not set\n// after\nargs := []string{\"--config\", \"my.toml\", \"shell\"}","handlingStrategy":"validation","validationCode":"func ensureRequired(flags *cmdflag.FlagSet, required []string, args []string) error {\n    _ = flags.Parse(args) // pre-parse or inspect raw args\n    for _, n := range required {\n        if !flags.Changed(n) {\n            return fmt.Errorf(\"pass --%s explicitly; it is required by this command\", n)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if m := regexp.MustCompile(`required flag\\(s\\) \"(.+)\" not set`).FindStringSubmatch(err.Error()); m != nil {\n        fmt.Fprintf(os.Stderr, \"missing required flag: --%s\\n\", m[1])\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["After upgrading the CLI, re-run scripts once with --help to catch newly required flags.","Default the value in the wrapper script: ${CFG:+--config $CFG} plus an error if unset.","Remember a registered default does not satisfy a required flag - Changed is set only by an explicit value.","Keep required-flag documentation in the command's Short/Long so users see it before failing."],"tags":["cli","cmdtree","required-flags","validation"],"backgroundTag":"missing-required-flag","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}