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

Why design global options need to be before subcommands? #1391

Closed
lizhifengones opened this issue May 8, 2022 · 6 comments
Closed

Why design global options need to be before subcommands? #1391

lizhifengones opened this issue May 8, 2022 · 6 comments
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this
Milestone

Comments

@lizhifengones
Copy link

Global options need to appear before subcommands, not anywhere, why are they designed this way?

This is not the same as spf13/cobra. In urfave/cli, global options are not visible in subcommands.

I like cobra's global options, but urfave/cli is simpler, that's why I use urfave/cli. Hope someone can explain my doubts...

# ./bin/test-cmd --debug aaa  (work)
# ./bin/test-cmd aaa --debug
2022/05/08 14:23:57 flag provided but not defined: -debug
@lizhifengones lizhifengones added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels May 8, 2022
@meatballhat meatballhat added this to the Release 2.x milestone May 8, 2022
@fjl
Copy link
Contributor

fjl commented May 11, 2022

I have to say, I find this extremely annoying as well. We use urfave/cli in go-ethereum, and are kind of stuck with it because we have so much code relying on it.

It would be nice to be able to tweak this behavior using e.g.

var app = cli.App{
    ...
    AllowAllFlagsInSubcommands: true,
}

and the implementation of it would be straightforward, just construct the flag set a bit differently.

@tonglil
Copy link

tonglil commented May 13, 2022

Funny, just stumbled upon this UX issue today as well. Was expecting app.Flags options to show up with every subcommand's help as well as a GLOBAL OPTIONS or something.

Cobra does this with local vs persistent flags: https://github.com/spf13/cobra/blob/master/user_guide.md#persistent-flags

Likely related:

I've also found that the help text seems to be fairly contrived with 3 different ways of triggering them and all with slightly different text when in my opinon they should all be the same..

Group 1 cli.AppHelpTemplate:

root -h
root --help
root help
root cmd help -> shows "GLOBAL OPTIONS" when it should show "COMMAND OPTIONS", but also used by `root help`

Group 2 cli.CommandHelpTemplate:

root help cmd

Group 3 cli.SubcommandHelpTemplate:

root cmd -h
root cmd --help

@Icarus9913
Copy link

Yeah, as @tonglil said. It would be nice to show Global options through the whole cmd cli phase from top to bottom.
For users to get understand the global options better.

@yxxhero
Copy link

yxxhero commented Jun 30, 2022

any update?

@dearchap
Copy link
Contributor

dearchap commented Jul 5, 2022

While this is a nice feature to have it is non trivial as it means that the entire flag parse needs to change. This has been discussed endlessly in the past. If you can provide a PR we can gladly comment and incorporate

@dearchap
Copy link
Contributor

Duplicate of #1113

@dearchap dearchap marked this as a duplicate of #1113 Oct 21, 2022
@dearchap dearchap closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
huiyifyj added a commit to Pengxn/go-xn that referenced this issue Mar 26, 2023
- Move '--config' flag from global options to 'web' subcommand.
- Set default '--config' flag value to 'fyj.ini'.

[cli](github.com/urfave/cli) library requires global flags before subcommands/arguments.
For refer to urfave/cli#1113, urfave/cli#1268 and urfave/cli#1391.
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/question someone asking a question status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

7 participants