Skip to content

Commit

Permalink
enhancing the cli text
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwelin committed Nov 1, 2022
1 parent c74f564 commit 9dd1e42
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion cmd/cassowary/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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"))
}

0 comments on commit 9dd1e42

Please sign in to comment.