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

v2 bug: multi-line UsageText doesn't consistently indent in help output #1278

Closed
4 tasks done
codefromthecrypt opened this issue Jun 1, 2021 · 2 comments · Fixed by #1279
Closed
4 tasks done

v2 bug: multi-line UsageText doesn't consistently indent in help output #1278

codefromthecrypt opened this issue Jun 1, 2021 · 2 comments · Fixed by #1279
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

@codefromthecrypt
Copy link

my urfave/cli version is

latest master

Checklist

  • Are you running the latest v2 release? 581b769
  • Did you check the manual for your release?
  • Did you perform a search about this problem? Looked at the issues list

Dependency Management

  • My project is using go modules.

Describe the bug

If your UsageText is multi-line, help output USAGE only indents the first line 4 spaces, not the others.

To reproduce

Add UsageText that includes at least one newline. Ex:

		Usage:     "Download and install a <version> of Envoy",
		ArgsUsage: "<version>",
		UsageText: fmt.Sprintf(`The '<version>' is from the "versions" command.
The Envoy <version> will be installed into $GETENVOY_HOME/versions/<version>

Example:
$ getenvoy install %s`, version.LastKnownEnvoy),

Observed behavior

The first line indents, but the others don't.

USAGE:
   The '<version>' is from the "versions" command and installed if necessary.
The '<args>' are interpreted by Envoy.
The Envoy working directory is archived as $GETENVOY_HOME/runs/$epochtime.tar.gz upon termination.

Example:
$ getenvoy run 1.18.3 --config-path ./bootstrap.yaml

Expected behavior

I would expect consistent indent because trying to manipulate UsageText to indent manually is awkward and fragile (ex guess 4 spaces)

Additional context

Before #1171 this wouldn't render at all. Now it renders, but not quite right.

Want to fix this yourself?

could if reviewing my work is easier than fixing directly

Run go version and paste its output here

go version go1.16.3 darwin/amd64

Run go env and paste its output here

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/adrian/Library/Caches/go-build"
GOENV="/Users/adrian/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/adrian/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/adrian/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.3/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/adrian/tetratelabs/getenvoy/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vd/1cf8zdb1721f4z5rjggy8bp40000gn/T/go-build2368530510=/tmp/go-build -gno-record-gcc-switches -fno-common"

@codefromthecrypt codefromthecrypt 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 1, 2021
@clok
Copy link
Contributor

clok commented Jun 2, 2021

I did some testing and digging on this issue. First, I believe that this is not a regression due to #1171. It appears to be in the code since at least v2.0.0 (I have not checked v1 at this point). Second, it should be a pretty straight forward feature to add.

The root cause is that the template used to generate the command help output will use the UsageText directly, with no formatting. See: https://github.com/urfave/cli/blob/master/template.go#L41-L43 The first line is indented by default due to the spacing in the template.

This should do the trick. I will open a PR to address this.

USAGE:
   {{if .UsageText}}{{.UsageText | nindent 3 | trim}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}

@clok
Copy link
Contributor

clok commented Jun 2, 2021

@codefromthecrypt and @rliebz Got a PR up to address this. #1279

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

Successfully merging a pull request may close this issue.

2 participants