cli icon indicating copy to clipboard operation
cli copied to clipboard

Why design global options need to be before subcommands?

Open lizhifengones opened this issue 2 years ago • 5 comments

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 avatar May 08 '22 06:05 lizhifengones

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.

fjl avatar May 11 '22 20:05 fjl

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:

  • https://github.com/urfave/cli/issues/734
  • https://github.com/urfave/cli/issues/585
  • https://github.com/urfave/cli/issues/427
  • https://github.com/urfave/cli/issues/1205
  • https://github.com/urfave/cli/pull/1245

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

tonglil avatar May 13 '22 23:05 tonglil

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.

Icarus9913 avatar May 26 '22 15:05 Icarus9913

any update?

yxxhero avatar Jun 30 '22 00:06 yxxhero

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 avatar Jul 05 '22 12:07 dearchap

Duplicate of #1113

dearchap avatar Oct 21 '22 19:10 dearchap