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

CustomHelpTemplate is ignored with --help flag #1703

Closed
3 tasks done
feedmeapples opened this issue Mar 15, 2023 · 2 comments · Fixed by #1728
Closed
3 tasks done

CustomHelpTemplate is ignored with --help flag #1703

feedmeapples opened this issue Mar 15, 2023 · 2 comments · Fixed by #1728
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

@feedmeapples
Copy link
Contributor

feedmeapples commented Mar 15, 2023

My urfave/cli version is

2.25.0

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
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.
  • My project is automatically downloading the latest version.

Describe the bug

While cli top-level-command help respects CustomHelpTemplate when printing help, cli top-level-command --help ignores it and prints SubcommandHelpTemplate instead.

Is this intentional? What is the purpose of SubcommandHelpTemplate?

If this is not intentional i can send a PR switching to CustomHelpTemplate

To reproduce

app := cli.NewApp()
	app.Name = "testapp"
        app.Commands = []*cli.Command{
		        {
			        Name:   "top-level-command",
			        Action: func(c *cli.Context) error { return nil },
			        CustomHelpTemplate: "TESTING",
			 }
}
go run ./cmd/app top-level-command --help

Observed behavior

It prints SubcommandHelpTemplate

Expected behavior

go run ./cmd/app top-level-command --help should print CustomHelpTemplate

Additional context

temporalio/cli#153

Want to fix this yourself?

Yes

Run go version and paste its output here

go version

Run go env and paste its output here

@feedmeapples feedmeapples 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 Mar 15, 2023
@dearchap
Copy link
Contributor

@feedmeapples Can you post your whole main.go file here. ? I want to double check some things. The behaviour is really really tricky to get right.

@jojje
Copy link

jojje commented Apr 30, 2023

Here's a small main.go that reproduces the issue.

package main

import (
	"log"
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	app := &cli.App{
		Name: "myapp",
		Commands: []*cli.Command{
			{
				Name:               "subcmd",
				CustomHelpTemplate: "My template",
				// HideHelpCommand:    true,
				Action: func(c *cli.Context) error {
					return nil
				},
			},
		},
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

This code has the right behavior,

$ go run main.go subcmd -h
My template

But if you comment in the HideHelpCommand line, the custom template is not used, but the default hard-coded one.

$ go run main.go subcmd -h
NAME:
   myapp subcmd

USAGE:
   myapp subcmd command [command options] [arguments...]

OPTIONS:
   --help, -h  show help

The problem seems to be here, where the fall-through results in the hard coded template being used.

jojje added a commit to jojje/urfave-cli that referenced this issue Apr 30, 2023
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.

3 participants