Flags are alphabetically sorted when using categories
NilsJPWerner opened this issue · comments
Nils Werner commented
My urfave/cli version is
github.com/urfave/cli/v2 v2.27.1
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 using vendoring.
- My project is automatically downloading the latest version.
- I am unsure of what my dependency management setup is.
Describe the bug
The docs state that flags are not sorted by default. However when using categories the flags within each category is sorted alphabetically. Furthermore the categories are also sorted alphabetically.
To reproduce
var TestCmd = &cli.Command{
Name: "test",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "B_flag_2",
Category: "B",
},
&cli.StringFlag{
Name: "B_flag_1",
Category: "B",
},
&cli.StringFlag{
Name: "A_flag_2",
Category: "A",
},
&cli.StringFlag{
Name: "A_flag_1",
Category: "A",
},
},
Action: func(c *cli.Context) error {
return nil
},
}
Observed behavior
NAME:
main test
USAGE:
main test [command options] [arguments...]
OPTIONS:
A
--A_flag_1 value
--A_flag_2 value
B
--B_flag_1 value
--B_flag_2 value
Expected behavior
NAME:
main test
USAGE:
main test [command options] [arguments...]
OPTIONS:
B
--B_flag_2 value
--B_flag_1 value
A
--A_flag_2 value
--A_flag_1 value
dearchap commented
@NilsJPWerner Yes that is the current behaviour. I agree it would be better to make it configurable(i.e sort or not) but at this point we arent adding any features to v2. Yes this is a bug but its not "security critical" so most likely we wont fix. We can do this for v3 . Would you like to make a PR for v3 ?
Nils Werner commented
Is v3 substantially different?
dearchap commented
Not really