Skip to content

Commit 597f760

Browse files
committed
Improve help command layout
1 parent 3200ba4 commit 597f760

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

cmd/root.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"strings"
78

89
"github.com/localstack/lstk/internal/api"
910
"github.com/localstack/lstk/internal/config"
@@ -38,6 +39,33 @@ var rootCmd = &cobra.Command{
3839
func init() {
3940
rootCmd.Version = version.Version()
4041
rootCmd.SetVersionTemplate(versionLine() + "\n")
42+
43+
rootCmd.InitDefaultHelpFlag()
44+
rootCmd.Flags().Lookup("help").Usage = "Show help"
45+
46+
rootCmd.InitDefaultVersionFlag()
47+
rootCmd.Flags().Lookup("version").Usage = "Show version"
48+
49+
usageTemplate := rootCmd.UsageTemplate()
50+
usageTemplate = strings.Replace(usageTemplate, "Available Commands:", "Commands:", 1)
51+
usageTemplate = strings.Replace(usageTemplate, "Flags:", "Options:", 1)
52+
usageTemplate = strings.Replace(
53+
usageTemplate,
54+
`Usage:{{if .Runnable}}
55+
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
56+
{{.CommandPath}} [command]{{end}}`,
57+
`Usage: {{if eq .CommandPath "lstk"}}lstk [options] [command]{{else}}{{.UseLine}}{{end}}{{if eq .CommandPath "lstk"}}
58+
59+
LSTK - LocalStack command-line interace{{end}}`,
60+
1,
61+
)
62+
usageTemplate = strings.ReplaceAll(usageTemplate, `Use "{{.CommandPath}} [command] --help" for more information about a command.`, "")
63+
usageTemplate = strings.TrimRight(usageTemplate, "\n")
64+
rootCmd.SetUsageTemplate(usageTemplate)
65+
66+
rootCmd.SetHelpTemplate(`{{if eq .CommandPath "lstk"}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}{{else}}{{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}}
67+
68+
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}{{end}}`)
4169
rootCmd.AddCommand(startCmd)
4270
}
4371

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
var versionCmd = &cobra.Command{
1111
Use: "version",
12-
Short: "Print the lstk version",
12+
Short: "Show version",
1313
Long: "Print version information for the lstk binary.",
1414
RunE: func(cmd *cobra.Command, args []string) error {
1515
_, err := fmt.Fprintln(cmd.OutOrStdout(), versionLine())

0 commit comments

Comments
 (0)