Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
Amaury-Behague opened this issue Jun 11, 2024 · 1 comment
Open
3 tasks done
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@Amaury-Behague
Copy link

Amaury-Behague commented Jun 11, 2024

My urfave/cli version is

v2.27.2

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here (this is broken btw)
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

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.

cli/command.go

Line 203 in 1210bdf

cmd.Usage = "A new cli application"

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'
@Amaury-Behague Amaury-Behague added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Jun 11, 2024
@dearchap
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants