urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
21.89k stars 1.69k forks source link

Default `cli.App.Usage` behaviour is very hard to override and leads to ugly help #1924

Open Amaury-Behague opened 2 weeks ago

Amaury-Behague commented 2 weeks ago

My urfave/cli version is

v2.27.2

Checklist

Dependency Management

Describe the bug

This line of the code doesn't allow to set an empty cli.App.Usage value, which together with the fact that helpNameTemplate is not configurable makes it hard to have a clean HELP: section in the CLI docs. https://github.com/urfave/cli/blob/1210bdf785b2bddda680a262acc84d5e7b583460/command.go#L203

To reproduce

Create a cli.App{Usage: ""} or cli.App{} struct and launch it with --help.

Observed behavior

It's not possible to remove the "A new cli application" string from the help. Setting Usage to " " also leaves the -. The only way I've found is to entirely override cli.AppHelpTemplate or set Usage: "\b\b ".

Expected behavior

I would like to be able to set Usage to "" without it being overridden, or at least be able to customize helpNameTemplate to be able to remove the part that uses Usage.

Want to fix this yourself?

We'd love to have more contributors on this project! If the fix for this bug is easily explained and very small, feel free to create a pull request for it.

Run go version and paste its output here

go version go1.22.2 darwin/arm64

Run go env and paste its output here

GO111MODULE='auto'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/redacted/Library/Caches/go-build'
GOENV='/Users/redacted/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/redacted/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/redacted/go'
GOROOT='/Users/redacted/sdk/go1.22.2'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/redacted/sdk/go1.22.2/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/redacted/cli_path/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/tp/x23ymr696x1fyzfy7rq7fr740000gp/T/go-build457189288=/tmp/go-build -gno-record-gcc-switches -fno-common'
dearchap commented 2 days ago

@Amaury-Behague You can set a custom template and override whatever you want in the help text. It is not very user friendly but anyone with a knowledge of go templating should be able to handle it. At this point v2 is in maint mode so we cannot make any changes to the current behavior. If you have an ideas we can incorporate them into v3.