spf13 / cobra

A Commander for modern Go CLI interactions
https://cobra.dev
Apache License 2.0
37.81k stars 2.83k forks source link

Persistent flags alone can't disable the ordering properly #1033

Open jaysun91 opened 4 years ago

jaysun91 commented 4 years ago

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")
...
dmayle commented 4 years ago

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
...
github-actions[bot] commented 4 years ago

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

nkuba commented 2 years ago

Hey :wave: any plans around fixing this issue?