-
Notifications
You must be signed in to change notification settings - Fork 5
/
index_cmd.go
31 lines (25 loc) · 906 Bytes
/
index_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package dcli
import (
"fmt"
"github.com/spf13/cobra"
)
// Index command, but short is not set. That is left to caller.
func IndexCmd(moduleName string) *cobra.Command {
return &cobra.Command{
Use: moduleName,
Short: fmt.Sprintf("Querying commands for the %s module", moduleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: indexRunCmd,
}
}
func indexRunCmd(cmd *cobra.Command, args []string) error {
usageTemplate := `Usage:{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}
{{if .HasAvailableSubCommands}}Available Commands:{{range .Commands}}{{if .IsAvailableCommand}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
cmd.SetUsageTemplate(usageTemplate)
return cmd.Help()
}