Skip to content

Commit 5cf2ba1

Browse files
committed
Update root usage
1 parent d9fc1c3 commit 5cf2ba1

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

cli/cmd/root.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,8 @@ var rootCmd = &cobra.Command{
7373
Long: `Deploy machine learning models in production`,
7474
}
7575

76-
// Copied from https://github.com/spf13/cobra/blob/master/command.go, in order to make the short descritpion start with lower case
77-
var helpCmd = &cobra.Command{
78-
Use: "help [command]",
79-
Short: "help about any command",
80-
Long: `help provides help for any command in the CLI.
81-
Type ` + rootCmd.Name() + ` help [path to command] for full details.`,
82-
Run: func(c *cobra.Command, args []string) {
83-
cmd, _, e := c.Root().Find(args)
84-
if cmd == nil || e != nil {
85-
c.Printf("Unknown help topic %#q\n", args)
86-
c.Root().Usage()
87-
} else {
88-
cmd.InitDefaultHelpFlag()
89-
cmd.Help()
90-
}
91-
},
92-
}
93-
9476
func Execute() {
9577
defer errors.RecoverAndExit()
96-
rootCmd.SetHelpCommand(helpCmd)
9778

9879
cobra.EnableCommandSorting = false
9980

@@ -111,10 +92,33 @@ func Execute() {
11192
rootCmd.AddCommand(supportCmd)
11293
rootCmd.AddCommand(completionCmd)
11394

95+
updateRootUsage()
96+
11497
printLeadingNewLine()
11598
rootCmd.Execute()
11699
}
117100

101+
func updateRootUsage() {
102+
defaultUsageFunc := rootCmd.UsageFunc()
103+
usage := rootCmd.UsageString()
104+
105+
rootCmd.SetUsageFunc(func(cmd *cobra.Command) error {
106+
if cmd.Use != "cortex" {
107+
return defaultUsageFunc(cmd)
108+
}
109+
110+
usage = strings.Replace(usage, "Usage:\n cortex [command]\n\nAliases:\n cortex, cx\n\n", "", 1)
111+
usage = strings.Replace(usage, "Available Commands:", "Deployment Commands:", 1)
112+
usage = strings.Replace(usage, "\n cluster", "\n\nCluster commands:\n cluster", 1)
113+
usage = strings.Replace(usage, "\n configure", "\n\nOther commands:\n configure", 1)
114+
usage = strings.Replace(usage, "\nUse \"cortex", " help help about any command\n\nFlags:\n -h, --help help for cortex\n\nUse \"cortex", 1)
115+
116+
cmd.Print(usage)
117+
118+
return nil
119+
})
120+
}
121+
118122
func printLeadingNewLine() {
119123
if len(os.Args) == 2 && os.Args[1] == "completion" {
120124
return

0 commit comments

Comments
 (0)