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

Display global flags in subcommand #734

Closed
xeals opened this issue Apr 11, 2018 · 15 comments · Fixed by #1949
Closed

Display global flags in subcommand #734

xeals opened this issue Apr 11, 2018 · 15 comments · Fixed by #1949
Labels
area/v2 relates to / is being considered for v2 help wanted please help if you can! kind/feature describes a code enhancement / feature request status/confirmed confirmed to be valid, but work has yet to start
Milestone

Comments

@xeals
Copy link

xeals commented Apr 11, 2018

Is it possible to display higher-level flags in a subcommand?

e.g., given:

app := &cli.App{
  Flags: []cli.Flag{
    cli.BoolFlag{
      Name: "verbose, v",
      Usage: "be LOUD",
    },
  },
  Commands: []cli.Command{
    cli.Command{
      Name: "status",
    },
  },
}

Is it possible for verbose to be displayed in status's help command without redefining the flag?

@nasu
Copy link

nasu commented May 3, 2018

GlobalXXX?

@genieplus
Copy link

I run into the same issue. I was expecting to see the option --verbose when the help of the subcommand status is printed. Something like:

$ go run main.go status -h
NAME:
   main status -

USAGE:
   main [global options] status [command options] [arguments...]

OPTIONS:
   --help, -h  show help (default: false)

GLOBAL OPTIONS:
   --verbose      be LOUD (default: false)

Just to be clear, it is not a question of defining a global flag as suggested in the previous comment. It is about the printed help.

@coilysiren coilysiren added help wanted please help if you can! status/confirmed confirmed to be valid, but work has yet to start kind/feature describes a code enhancement / feature request labels Aug 17, 2019
@coilysiren
Copy link
Member

Mostly for bookkeeping, I want to mention that this is conceptually related to my desire to expand global flags support for v3 #833

@coilysiren coilysiren added status/in-review needs to be reviewed by maintainers before it is accepted and removed status/confirmed confirmed to be valid, but work has yet to start labels Sep 10, 2019
@coilysiren
Copy link
Member

This feature is now in review, @urfave/cli please add a 👍 or 👎 to the top post if you're in favor or against this feature being added!

@coilysiren coilysiren removed the help wanted please help if you can! label Sep 10, 2019
@coilysiren coilysiren added area/v2 relates to / is being considered for v2 and removed area/v2 relates to / is being considered for v2 labels Nov 27, 2019
@stale
Copy link

stale bot commented Feb 25, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Feb 25, 2020
@coilysiren
Copy link
Member

I'm not sure if this is still relevant as of v2?

@stale
Copy link

stale bot commented Feb 26, 2020

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Feb 26, 2020
@bandesz
Copy link

bandesz commented Mar 10, 2020

This issue is still present in v2.

@coilysiren
Copy link
Member

Thanks for the confirmation! 👍

@coilysiren coilysiren added help wanted please help if you can! status/confirmed confirmed to be valid, but work has yet to start and removed status/in-review needs to be reviewed by maintainers before it is accepted labels Mar 10, 2020
@bandesz
Copy link

bandesz commented Mar 10, 2020

I did a simple hack to always show the app global flags by overriding the cli.HelpPrinterCustom function:

globalOptionsTemplate := `{{if .VisibleFlags}}GLOBAL OPTIONS:
   {{range $index, $option := .VisibleFlags}}{{if $index}}
   {{end}}{{$option}}{{end}}
{{end}}
`

app := &cli.App {...}

origHelpPrinterCustom := cli.HelpPrinterCustom
defer func() {
  cli.HelpPrinterCustom = origHelpPrinterCustom
}()
cli.HelpPrinterCustom = func(out io.Writer, templ string, data interface{}, customFuncs map[string]interface{}) {
	origHelpPrinterCustom(out, templ, data, customFuncs)
	if data != app {
		origHelpPrinterCustom(app.Writer, globalOptionsTemplate, app, nil)
	}
}
if err := app.Run(os.Args); err != nil {
  //...
}

@stale
Copy link

stale bot commented Jun 8, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Jun 8, 2020
@stale
Copy link

stale bot commented Jul 8, 2020

Closing this as it has become stale.

@stale stale bot closed this as completed Jul 8, 2020
@Madhur1997
Copy link
Contributor

I had a similar requirement. Is there any progress on this?
I can get a PR if this is still open.

@factoidforrest
Copy link

factoidforrest commented Dec 16, 2021

It would be better if the global flags worked after a subcommand, optionally. In our tool it makes much more sense to do
tool subcommand --flag
than
tool --flag subcommand

@meatballhat meatballhat reopened this Apr 22, 2022
@meatballhat meatballhat removed the status/stale stale due to the age of it's last update label Apr 22, 2022
@dearchap dearchap mentioned this issue Sep 12, 2022
3 tasks
@dearchap dearchap added status/claimed someone has claimed this issue area/v2 relates to / is being considered for v2 labels Oct 27, 2022
@dearchap dearchap self-assigned this Oct 27, 2022
@dearchap dearchap removed the status/claimed someone has claimed this issue label Oct 30, 2022
@dearchap dearchap removed their assignment Oct 30, 2022
@decentral1se
Copy link

#1949

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 help wanted please help if you can! kind/feature describes a code enhancement / feature request status/confirmed confirmed to be valid, but work has yet to start
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants