kong
kong copied to clipboard
Expose some private functions for printing help
I'm building a cli tool with some custom help output but want it to look similar to the default help output. It would be nice if these private functions were exposed so it's easier to use these help functions to build something custom. This PR doesn't change any functionality and is purely for exposing private functions.
Please feel free to edit or let me know what to change. I can also extract these to a separate package if that is more desirable.
P.S. Thanks for building and maintaining this awesome library. 🙏
Overall LGTM, but let's move it into a separate package, perhaps helpwriter.
Ping on last comment?
Sorry been a little distracted and am current in India for a few weeks. I'll get around to this in May. Feel free to take charge of the PR if you want to make this happen sooner.
All good, no hurry :)
So, i tried to split apart the code but it doesn't really work nicely. For example, HelpWriter depends on Flag, HelpValueFormatter, HelpOptions, Node, and Positional but there isn't really an easy way to avoid a circular dependency without breaking changes. If i move these structs into a shared types package, it would be a breaking change. I could add interfaces that return each value HelpWriter needs via a method call and then add the methods to the objects but that is pretty ugly imo. Do you want me to go down the interfaces route or would you rather leave this as is?
One alternative thing i can try to do is to make the WriteX functions into methods so func WriteFlags(w *HelpWriter, groups [][]*Flag) would become func (w *HelpWriter) WriteFlags(groups [][]*Flag). This would reduce the global space pollution.
I did what i was saying above with making functions into methods and pushed the code. LMK if you like it and hopefully the linter passes. 🤞
Any news on this? I'm assuming this would help solve https://github.com/alecthomas/kong/issues/33?
EDIT: Commented on a workaround here.