flaggy icon indicating copy to clipboard operation
flaggy copied to clipboard

Sorting of flags

Open syacko opened this issue 4 years ago • 5 comments

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 avatar Jun 17 '20 20:06 syacko

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

syacko avatar Jun 17 '20 21:06 syacko

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?

integrii avatar Jun 22 '20 19:06 integrii

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

syacko avatar Jun 22 '20 19:06 syacko

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()
...

integrii avatar Jul 15 '20 14:07 integrii

Thank sounds great. Thank you.

soteadmin avatar Jul 15 '20 16:07 soteadmin