Mirrors internal/cmdpolicy/apply.go::installDenyStub: DisableFlagParsing + ArbitraryArgs keep cobra from short-circuiting with "missing required flag" before our RunE runs; leaf-level PersistentPreRunE defeats cobra's "first PreRunE wins" walk-up that would otherwise shadow the stub.
(svc *cobra.Command, service string, brand core.LarkBrand)
| 173 | // before our RunE runs; leaf-level PersistentPreRunE defeats cobra's "first |
| 174 | // PreRunE wins" walk-up that would otherwise shadow the stub. |
| 175 | func installBrandRestrictionGuard(svc *cobra.Command, service string, brand core.LarkBrand) { |
| 176 | stub := func(c *cobra.Command, _ []string) error { |
| 177 | c.SilenceUsage = true |
| 178 | return errs.NewValidationError(errs.SubtypeFailedPrecondition, |
| 179 | "the %q feature is not yet supported on the %s brand", |
| 180 | service, brand, |
| 181 | ) |
| 182 | } |
| 183 | noopPreRun := func(c *cobra.Command, _ []string) error { |
| 184 | c.SilenceUsage = true |
| 185 | return nil |
| 186 | } |
| 187 | var walk func(c *cobra.Command) |
| 188 | walk = func(c *cobra.Command) { |
| 189 | c.Hidden = true |
| 190 | c.DisableFlagParsing = true |
| 191 | c.Args = cobra.ArbitraryArgs |
| 192 | c.PreRunE = nil |
| 193 | c.PreRun = nil |
| 194 | c.PersistentPreRunE = noopPreRun |
| 195 | c.PersistentPreRun = nil |
| 196 | c.RunE = stub |
| 197 | c.Run = nil |
| 198 | for _, child := range c.Commands() { |
| 199 | walk(child) |
| 200 | } |
| 201 | } |
| 202 | walk(svc) |
| 203 | |
| 204 | // --help bypasses RunE, so surface the restriction in Long too. |
| 205 | svc.Long = fmt.Sprintf("The %q feature is not yet supported on the %s brand.", service, brand) |
| 206 | } |
| 207 | |
| 208 | // Sheets backward-compatibility help grouping. |
| 209 | // |
no test coverage detected