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

Function subcommandOnlyFlagTokens

cmd/root.go:485–497  ·  view source on GitHub ↗

subcommandOnlyFlagTokens returns the flag tokens in rawArgs that are valid on a subcommand of cmd but not on cmd itself/inherited — flags supplied while omitting the subcommand they belong to (`im --format json`). Global flags valid on the bare group (e.g. --profile) are excluded so `lark-cli --prof

(cmd *cobra.Command, rawArgs []string)

Source from the content-addressed store, hash-verified

483// valid on the bare group (e.g. --profile) are excluded so
484// `lark-cli --profile p im` still prints help rather than erroring.
485func subcommandOnlyFlagTokens(cmd *cobra.Command, rawArgs []string) []string {
486 var misplaced []string
487 for _, a := range flagTokensInArgs(rawArgs) {
488 name := strings.SplitN(strings.TrimLeft(a, "-"), "=", 2)[0]
489 if name == "" || flagKnownOnGroup(cmd, name) {
490 continue
491 }
492 if flagDefinedInTree(cmd, name) {
493 misplaced = append(misplaced, a)
494 }
495 }
496 return misplaced
497}
498
499// flagDefinedInTree reports whether name is defined on cmd, its inherited
500// (persistent) flags, or any direct subcommand. The subcommand case covers a

Callers 1

unknownSubcommandRunEFunction · 0.85

Calls 3

flagTokensInArgsFunction · 0.85
flagKnownOnGroupFunction · 0.85
flagDefinedInTreeFunction · 0.85

Tested by

no test coverage detected