MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Execute

Method Execute

cf/commands/help.go:48–101  ·  view source on GitHub ↗
(c flags.FlagContext)

Source from the content-addressed store, hash-verified

46}
47
48func (cmd *Help) Execute(c flags.FlagContext) error {
49 if len(c.Args()) == 0 {
50 help.ShowHelp(cmd.ui.Writer(), help.GetHelpTemplate())
51 } else {
52 cmdName := c.Args()[0]
53 if commandregistry.Commands.CommandExists(cmdName) {
54 cmd.ui.Say(commandregistry.Commands.CommandUsage(cmdName))
55 } else {
56 // check plugin commands
57 found := false
58 for _, meta := range cmd.config.Plugins() {
59 for _, c := range meta.Commands {
60 if c.Name == cmdName || c.Alias == cmdName {
61 output := T("NAME:") + "\n"
62 output += " " + c.Name + " - " + c.HelpText + "\n"
63
64 if c.Alias != "" {
65 output += "\n" + T("ALIAS:") + "\n"
66 output += " " + c.Alias + "\n"
67 }
68
69 output += "\n" + T("USAGE:") + "\n"
70 output += " " + c.UsageDetails.Usage + "\n"
71
72 if len(c.UsageDetails.Options) > 0 {
73 output += "\n" + T("OPTIONS:") + "\n"
74
75 // find longest name length
76 l := 0
77 for n := range c.UsageDetails.Options {
78 if len(n) > l {
79 l = len(n)
80 }
81 }
82
83 for n, f := range c.UsageDetails.Options {
84 output += " -" + n + strings.Repeat(" ", 7+(l-len(n))) + f + "\n"
85 }
86 }
87
88 cmd.ui.Say(output)
89
90 found = true
91 }
92 }
93 }
94
95 if !found {
96 return errors.New("'" + cmdName + "' is not a registered command. See 'cf help -a'")
97 }
98 }
99 }
100 return nil
101}

Callers

nothing calls this directly

Calls 8

ShowHelpFunction · 0.92
GetHelpTemplateFunction · 0.92
CommandExistsMethod · 0.80
CommandUsageMethod · 0.80
ArgsMethod · 0.65
WriterMethod · 0.65
SayMethod · 0.65
PluginsMethod · 0.65

Tested by

no test coverage detected