From 9dd1e42e9aaef83db888cb9ac6eebf40ecba3d2e Mon Sep 17 00:00:00 2001 From: rogerwelin Date: Tue, 1 Nov 2022 22:13:24 +0100 Subject: [PATCH] enhancing the cli text --- cmd/cassowary/cli.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/cmd/cassowary/cli.go b/cmd/cassowary/cli.go index 92ffcea..17f53f4 100644 --- a/cmd/cassowary/cli.go +++ b/cmd/cassowary/cli.go @@ -221,10 +221,11 @@ func validateCLI(c *cli.Context) error { func runCLI(args []string) { app := cli.NewApp() app.Name = "cassowary - 學名" + setCustomCLITemplate(app) app.HelpName = "cassowary" app.UsageText = "cassowary [command] [command options] [arguments...]" app.EnableBashCompletion = true - app.Usage = "" + app.Usage = "Modern cross-platform HTTP load-testing tool" app.Version = version app.Commands = []*cli.Command{ { @@ -342,3 +343,40 @@ func runCLI(args []string) { os.Exit(0) } } + +func setCustomCLITemplate(c *cli.App) { + whiteBold := color.New(color.Bold).SprintfFunc() + whiteUnderline := color.New(color.Bold).Add(color.Underline).SprintfFunc() + cyan := color.New(color.FgCyan).SprintFunc() + + c.CustomAppHelpTemplate = fmt.Sprintf(` %s: + {{.Name}}{{if .Usage}} - {{.Usage}}{{end}}{{if .Description}} + + DESCRIPTION: + {{.Description | nindent 3 | trim}}{{end}}{{if len .Authors}} + + AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: + {{range $index, $author := .Authors}}{{if $index}} + {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}} + + %s:{{range .VisibleCategories}}{{if .Name}} + {{.Name}}:{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + + %s: + {{range $index, $option := .VisibleFlags}}{{if $index}} + {{end}}{{$option}}{{end}}{{end}}{{if .Copyright}} + + COPYRIGHT: + {{.Copyright}}{{end}} + + %s + Example running cassowary against a target with 100 requests using 10 concurrent users + %s + `, whiteBold("NAME"), + whiteBold("COMMANDS"), + whiteBold("GLOBAL OPTIONS"), + whiteUnderline("Example"), + cyan("$ cassowary run -u http://www.example.com -c 10 -n 100")) +}