cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Persistent flags alone can't disable the ordering properly

Open jaysun91 opened this issue 5 years ago • 3 comments

It looks like the disable ordering feature is not working with commands with persistent flags only. But works fine if commands have local flags or both local and persistent flags.

I have a root command with only persistent flags. And even I set SortFlags = false, the command still prints the flags in order.

...
	pFlags := c.PersistentFlags()
	pFlags.SortFlags = false
	pFlags.String("z", "Z", "")
	pFlags.String("a", "A", "")
...

And I got

...
Flags:
      --a string    (default "A")
      --z string    (default "Z")
...

jaysun91 avatar Feb 12 '20 00:02 jaysun91

If you also set Flags().SortFlags to false, even without defining local flags, then the sorting will be disabled

...
        c.Flags().SortFlags = false
        pFlags := c.PersistentFlags
...

dmayle avatar Mar 03 '20 13:03 dmayle

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar May 03 '20 00:05 github-actions[bot]

Hey :wave: any plans around fixing this issue?

nkuba avatar Aug 31 '22 06:08 nkuba