integrii / flaggy

Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.
The Unlicense
856 stars 30 forks source link

Sorting of flags #69

Open syacko opened 4 years ago

syacko commented 4 years ago

I have reviewed the documentation and I don't see a way to sort the out put of the flags when -h(elp) is used. Is this possible and if not, is it something that can be added?

syacko commented 4 years ago

After experimenting, the flags are listed in the order they appear in the code. Please confirm that is correct.

integrii commented 4 years ago

I am not sure if how flags are listed is always the same (or always based on the code), actually, but we could add sorting to them - it's probably relatively easy... Right before the flags are templated out into the help display, we could do some analysis that sorts their order in the slice.

It is likely the case that flags are almost always displayed in the order that they are appended, but flags that are inherited from parent subcommands may break this rule... That is, flags that are part of a parent subcommand may come out before or after depending on how the code runs.

What kind of flag output sorting would you prefer to see?

syacko commented 4 years ago

Thanks for the reply. A simple A-Z or Z-A would be great by the long name.

integrii commented 4 years ago

We could add a couple calls to flaggy that enable flag output sorting. Then, right before output, we sort depending on which sorting method was chosen.

flaggy.SortFlagsByLongName()
flaggy.SortFlagsByLongNameReversed()
...
soteadmin commented 4 years ago

Thank sounds great. Thank you.