MCPcopy
hub / github.com/spf13/cobra / writeFlags

Function writeFlags

bash_completions.go:551–591  ·  view source on GitHub ↗
(buf io.StringWriter, cmd *Command)

Source from the content-addressed store, hash-verified

549}
550
551func writeFlags(buf io.StringWriter, cmd *Command) {
552 prepareCustomAnnotationsForFlags(cmd)
553 WriteStringAndCheck(buf, ` flags=()
554 two_word_flags=()
555 local_nonpersistent_flags=()
556 flags_with_completion=()
557 flags_completion=()
558
559`)
560
561 if cmd.DisableFlagParsing {
562 WriteStringAndCheck(buf, " flag_parsing_disabled=1\n")
563 }
564
565 localNonPersistentFlags := cmd.LocalNonPersistentFlags()
566 cmd.NonInheritedFlags().VisitAll(func(flag *pflag.Flag) {
567 if nonCompletableFlag(flag) {
568 return
569 }
570 writeFlag(buf, flag, cmd)
571 if len(flag.Shorthand) > 0 {
572 writeShortFlag(buf, flag, cmd)
573 }
574 // localNonPersistentFlags are used to stop the completion of subcommands when one is set
575 // if TraverseChildren is true we should allow to complete subcommands
576 if localNonPersistentFlags.Lookup(flag.Name) != nil && !cmd.Root().TraverseChildren {
577 writeLocalNonPersistentFlag(buf, flag)
578 }
579 })
580 cmd.InheritedFlags().VisitAll(func(flag *pflag.Flag) {
581 if nonCompletableFlag(flag) {
582 return
583 }
584 writeFlag(buf, flag, cmd)
585 if len(flag.Shorthand) > 0 {
586 writeShortFlag(buf, flag, cmd)
587 }
588 })
589
590 WriteStringAndCheck(buf, "\n")
591}
592
593func writeRequiredFlag(buf io.StringWriter, cmd *Command) {
594 WriteStringAndCheck(buf, " must_have_one_flag=()\n")

Callers 1

genFunction · 0.85

Calls 10

WriteStringAndCheckFunction · 0.85
nonCompletableFlagFunction · 0.85
writeFlagFunction · 0.85
writeShortFlagFunction · 0.85
NonInheritedFlagsMethod · 0.80
RootMethod · 0.80
InheritedFlagsMethod · 0.80

Tested by

no test coverage detected