www.fgks.org   »   [go: up one dir, main page]

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

Flags are alphabetically sorted when using categories #1914

Open
3 tasks done
NilsJPWerner opened this issue May 24, 2024 · 3 comments
Open
3 tasks done

Flags are alphabetically sorted when using categories #1914

NilsJPWerner opened this issue May 24, 2024 · 3 comments
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

@NilsJPWerner
Copy link

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    
@NilsJPWerner NilsJPWerner 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 May 24, 2024
@dearchap
Copy link
Contributor

@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 ?

@NilsJPWerner
Copy link
Author

Is v3 substantially different?

@dearchap
Copy link
Contributor

Not really

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