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

Function writeRequiredFlag

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

Source from the content-addressed store, hash-verified

591}
592
593func writeRequiredFlag(buf io.StringWriter, cmd *Command) {
594 WriteStringAndCheck(buf, " must_have_one_flag=()\n")
595 flags := cmd.NonInheritedFlags()
596 flags.VisitAll(func(flag *pflag.Flag) {
597 if nonCompletableFlag(flag) {
598 return
599 }
600 if _, ok := flag.Annotations[BashCompOneRequiredFlag]; ok {
601 format := " must_have_one_flag+=(\"--%s"
602 if flag.Value.Type() != "bool" {
603 format += "="
604 }
605 format += cbn
606 WriteStringAndCheck(buf, fmt.Sprintf(format, flag.Name))
607
608 if len(flag.Shorthand) > 0 {
609 WriteStringAndCheck(buf, fmt.Sprintf(" must_have_one_flag+=(\"-%s"+cbn, flag.Shorthand))
610 }
611 }
612 })
613}
614
615func writeRequiredNouns(buf io.StringWriter, cmd *Command) {
616 WriteStringAndCheck(buf, " must_have_one_noun=()\n")

Callers 1

genFunction · 0.85

Calls 4

WriteStringAndCheckFunction · 0.85
nonCompletableFlagFunction · 0.85
NonInheritedFlagsMethod · 0.80
TypeMethod · 0.80

Tested by

no test coverage detected