diff --git a/README.md b/README.md index ad36f3c..79d8aaa 100644 --- a/README.md +++ b/README.md @@ -134,25 +134,31 @@ Output example: ```sh $ go run examples/main.go -h -# NAME: enve [OPTIONS] COMMAND - +# enve 0.0.0 # Run a program in a modified environment using .env files +# USAGE: +# enve [OPTIONS] COMMAND +# # OPTIONS: -# -f --file Load environment variables from a file path [default: .env] -# -V --verbose Enable more verbose info [default: false] [env: ENV_VERBOSE] -# -h --help Prints help information -# -v --version Prints version information - +# -f --file Load environment variables from a file path. +# Some new line description +# Another new line description. [default: .env] +# -b,-z --int Int value [default: 5] +# -V --verbose Enable more verbose info [default: true] [env: ENV_VERBOSE] +# -h --help Prints help information +# -v --version Prints version information +# # COMMANDS: -# info Show command information - +# info Show command information +# # Run 'enve COMMAND --help' for more information on a command $ go run examples/main.go -v # Version: 0.0.0 -# Go version: go1.15.4 -# Built: 2020-11-10T21:11:36 +# Go version: go1.16.2 +# Built: 2021-03-28T20:03:04 +# Commit: 1885ad1 # OS/Arch: linux/amd64 ``` diff --git a/app_printing.go b/app_printing.go index d472452..17cf682 100644 --- a/app_printing.go +++ b/app_printing.go @@ -20,6 +20,7 @@ func printHelp(app *App, cmd *Cmd) error { return fmt.Errorf("application instance not found") } + paddingLeft := strings.Repeat(" ", 3) summary := app.Summary flags := app.Flags if cmd != nil { @@ -27,13 +28,16 @@ func printHelp(app *App, cmd *Cmd) error { flags = cmd.Flags } + fmt.Printf("%s %s\n", app.Name, app.Version) + fmt.Printf("%s\n\n", summary) + // TODO: subcommands support + fmt.Println("USAGE:") if cmd == nil { - fmt.Printf("NAME: %s [OPTIONS] COMMAND\n\n", app.Name) + fmt.Printf("%s%s [OPTIONS] COMMAND\n\n", paddingLeft, app.Name) } else { - fmt.Printf("NAME: %s %s [OPTIONS] COMMAND\n\n", app.Name, cmd.Name) + fmt.Printf("%s%s %s [OPTIONS]\n\n", paddingLeft, app.Name, cmd.Name) } - fmt.Printf("%s\n\n", summary) // Print options fmt.Printf("OPTIONS:\n") @@ -101,7 +105,11 @@ func printHelp(app *App, cmd *Cmd) error { defaultVal := strings.TrimSpace(v.defaults) if defaultVal != "" { - defaultVal = " [default: " + defaultVal + "]" + defaultSpace := "" + if v.summary != "" { + defaultSpace = " " + } + defaultVal = defaultSpace + "[default: " + defaultVal + "]" } envVar := strings.TrimSpace(v.envVar) if envVar != "" { @@ -109,17 +117,17 @@ func printHelp(app *App, cmd *Cmd) error { } line := fmt.Sprintf( - " %s%s --%s%s %s%s%s\n", + "%s%s%s --%s%s%s", + paddingLeft, marginLeftRepeat, shorts, v.name, marginRightRepeat, - v.summary, - defaultVal, - envVar, + paddingLeft, ) - fmt.Println(line) + summary := strings.ReplaceAll(v.summary, "\n", "\n"+strings.Repeat(" ", len(line))) + fmt.Println(line + summary + defaultVal + envVar) } // Print app commands @@ -138,9 +146,11 @@ func printHelp(app *App, cmd *Cmd) error { } for _, c := range vcmds { fmt.Printf( - " %s%s%s %s\n", + "%s%s%s%s%s%s\n", + paddingLeft, "", c[0], + paddingLeft, strings.Repeat( " ", cmdLen-len([]rune(c[0])), ), @@ -153,10 +163,9 @@ func printHelp(app *App, cmd *Cmd) error { } } else { fmt.Printf("\n") - fmt.Printf("Run '%s %s COMMAND --help' for more information on a command\n", app.Name, cmd.Name) + fmt.Printf("Run '%s %s --help' for more information about this command\n", app.Name, cmd.Name) } - fmt.Printf("\n") return nil } diff --git a/app_printing_test.go b/app_printing_test.go index 73da652..2408246 100644 --- a/app_printing_test.go +++ b/app_printing_test.go @@ -47,6 +47,7 @@ func newApp(appHandler func(ctx *AppContext) error, cmdHandler func(ctx *CmdCont }, FlagString{ Name: "FF", + Summary: "abcde", Value: ".env", Aliases: []string{"f"}, EnvVar: "FF_ENV_VAR", diff --git a/examples/main.go b/examples/main.go index f481b87..2a028b7 100644 --- a/examples/main.go +++ b/examples/main.go @@ -25,7 +25,7 @@ func main() { app.Flags = []cli.Flag{ cli.FlagString{ Name: "file", - Summary: "Load environment variables from a file path", + Summary: "Load environment variables from a file path.\nSome new line description\nAnother new line description.", Value: ".env", Aliases: []string{"f"}, }, @@ -33,7 +33,7 @@ func main() { Name: "int", Summary: "Int value", Value: 5, - Aliases: []string{"b"}, + Aliases: []string{"b", "z"}, }, cli.FlagBool{ Name: "verbose",