From 765fa5d750af7ace6bc3311761fcf4133d0cc04d Mon Sep 17 00:00:00 2001 From: Hurng-Chun Lee Date: Mon, 4 Nov 2019 13:11:05 +0100 Subject: [PATCH] improve usage messages --- internal/cmd/cluster.go | 27 +++++++++++++++------------ internal/cmd/root.go | 13 ++++++++----- internal/cmd/webhook.go | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/internal/cmd/cluster.go b/internal/cmd/cluster.go index 40bd762..7ac7a00 100644 --- a/internal/cmd/cluster.go +++ b/internal/cmd/cluster.go @@ -216,9 +216,12 @@ var jobCmd = &cobra.Command{ } var jobTraceCmd = &cobra.Command{ - Use: "trace [JobID]", - Short: "Print job's trace log available on the Torque server.", - Long: ``, + Use: "trace [id]", + Short: "Print trace log of a job.", + Long: `Print trace log of a job retrieved from the Torque server. + +Only the trace log recorded in the last 3 days will be shown. +`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { c := trqhelper.TorqueHelperSrvClient{ @@ -233,7 +236,7 @@ var jobTraceCmd = &cobra.Command{ } var jobMeminfoCmd = &cobra.Command{ - Use: "meminfo [JobID]", + Use: "meminfo [id]", Short: "Print memory usage of a running job.", Long: ``, Args: cobra.MinimumNArgs(1), @@ -273,8 +276,8 @@ var nodeCmd = &cobra.Command{ } var nodeMeminfoCmd = &cobra.Command{ - Use: "memfree {access|compute}", - Short: "Print total and free memory on the cluster nodes.", + Use: "memfree [access|compute]", + Short: "Print total and free memory of cluster nodes.", Long: ``, ValidArgs: []string{nodeTypeNames[access], nodeTypeNames[compute]}, Run: func(cmd *cobra.Command, args []string) { @@ -295,8 +298,8 @@ var nodeMeminfoCmd = &cobra.Command{ } var nodeDiskinfoCmd = &cobra.Command{ - Use: "diskfree {access|compute}", - Short: "Print total and free disk space of the cluster nodes.", + Use: "diskfree [access|compute]", + Short: "Print total and free disk space of cluster nodes.", Long: ``, ValidArgs: []string{nodeTypeNames[access], nodeTypeNames[compute]}, Run: func(cmd *cobra.Command, args []string) { @@ -317,7 +320,7 @@ var nodeDiskinfoCmd = &cobra.Command{ } var nodeInfoCmd = &cobra.Command{ - Use: "info {access|compute}", + Use: "info [access|compute]", Short: "Print system load and resource availability of cluster nodes.", Long: ``, ValidArgs: []string{nodeTypeNames[access], nodeTypeNames[compute]}, @@ -339,9 +342,9 @@ var nodeInfoCmd = &cobra.Command{ } var nodeVncCmd = &cobra.Command{ - Use: "vnc [{host1} {host2} ...]", - Short: "Print list of VNC servers on the cluster or a specific node.", - Long: `Print list of VNC servers on the cluster or a specific node. + Use: "vnc [host1 host2 ...]", + Short: "Print VNC servers in the cluster or on specific nodes.", + Long: `Print VNC servers in the cluster or on specific nodes. If the {hostname} is specified, only the VNCs on the node will be shown. diff --git a/internal/cmd/root.go b/internal/cmd/root.go index e4f16c5..a43cb04 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -100,7 +100,6 @@ var availCmd = &cobra.Command{ table.SetHeader([]string{"Command", "Description"}) table.SetRowSeparator("-") addCommandUseToTable(rootCmd, "", table) - table.SetColWidth(40) table.Render() }, } @@ -109,10 +108,14 @@ var availCmd = &cobra.Command{ // `tablewritter.Table`. func addCommandUseToTable(cmd *cobra.Command, parentUse string, table *tablewriter.Table) { for _, c := range cmd.Commands() { - table.Append([]string{ - fmt.Sprintf("%s %s %s", parentUse, cmd.Use, c.Use), - c.Short, - }) + + // only prints the command itself if there is no further sub-commands + if len(c.Commands()) == 0 { + table.Append([]string{ + fmt.Sprintf("%s %s %s", parentUse, cmd.Use, c.Use), + c.Short, + }) + } addCommandUseToTable(c, fmt.Sprintf("%s %s", parentUse, cmd.Use), table) } } diff --git a/internal/cmd/webhook.go b/internal/cmd/webhook.go index 8878c01..80b4de2 100644 --- a/internal/cmd/webhook.go +++ b/internal/cmd/webhook.go @@ -42,7 +42,7 @@ var webhookCmd = &cobra.Command{ } var createCmd = &cobra.Command{ - Use: "create [ScriptPath]", + Use: "create [path]", Short: "Create a new webhook.", Long: ``, Args: func(cmd *cobra.Command, args []string) error {