MCPcopy Index your code
hub / github.com/larksuite/cli / flagDefinedInTree

Function flagDefinedInTree

cmd/root.go:504–525  ·  view source on GitHub ↗

flagDefinedInTree reports whether name is defined on cmd, its inherited (persistent) flags, or any direct subcommand. The subcommand case covers a user who merely omitted the subcommand — e.g. `sheets --format json`, where --format is injected on every leaf shortcut, not on the group — so only a gen

(cmd *cobra.Command, name string)

Source from the content-addressed store, hash-verified

502// --format is injected on every leaf shortcut, not on the group — so only a
503// genuinely unknown flag like `sheets --badflag` is reported.
504func flagDefinedInTree(cmd *cobra.Command, name string) bool {
505 short := len(name) == 1
506 known := func(c *cobra.Command, inherited bool) bool {
507 fs := c.Flags()
508 if inherited {
509 fs = c.InheritedFlags()
510 }
511 if short {
512 return fs.ShorthandLookup(name) != nil
513 }
514 return fs.Lookup(name) != nil
515 }
516 if known(cmd, false) || known(cmd, true) {
517 return true
518 }
519 for _, c := range cmd.Commands() {
520 if known(c, false) {
521 return true
522 }
523 }
524 return false
525}
526
527// availableSubcommandNames returns the invokable subcommand names of cmd, split
528// into current commands and backward-compatibility aliases (those tagged into

Callers 2

unknownFlagTokensFunction · 0.85
subcommandOnlyFlagTokensFunction · 0.85

Calls 1

LookupMethod · 0.80

Tested by

no test coverage detected