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

subcommand help did show global options. #1881

Closed
yorkz1994 opened this issue Apr 1, 2024 · 1 comment
Closed

subcommand help did show global options. #1881

yorkz1994 opened this issue Apr 1, 2024 · 1 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

Comments

@yorkz1994
Copy link

My urfave/cli version is

V2.27.1

Checklist

Dependency Management

Describe the bug

Help for subcommand does not show global options, this can lead to confusion if global flag is required because when call subcommand, it always show help of subcommand instead of running it. And you will never know why it does not run subcommand and always show subcommand help.

To reproduce

package main

import (
	"fmt"
	"os"

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

func main() {
	app := &cli.App{
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name: "s",
				Required: true,
			},
		},
		Commands: []*cli.Command{
			{
				Name:  "add",
				Usage: "add a task to the list",
				Flags: []cli.Flag{
					&cli.IntFlag{
						Name: "i",
					},
				},
				Action: func(cCtx *cli.Context) error {
					fmt.Println("add")
					return nil
				},
			},
		},
	}
	app.Run(os.Args)
}

Observed behavior

go run main.go add
NAME:
   main.exe add - add a task to the list

USAGE:
   main.exe add [command options] [arguments...]

OPTIONS:
   -i value    (default: 0)
   --help, -h  show help

If run subcommand, it will show help of add instead of running it. Because no global option in the subcommand help output, you never know that is caused by missing a required global option "s". If I set global option to not required, then subcommand add will be executed.

Expected behavior

When run help subcommand, it should show global options.

@yorkz1994 yorkz1994 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 Apr 1, 2024
@dearchap
Copy link
Contributor

dearchap commented Apr 1, 2024

@yorkz1994 This is a duplicate of #734 . We dont have support for this in v2. If you want to push a PR onto v3 with this support I will be glad to review.

@dearchap dearchap closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
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