kong icon indicating copy to clipboard operation
kong copied to clipboard

Expose some private functions for printing help

Open atishpatel opened this issue 3 years ago • 9 comments

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. 🙏

atishpatel avatar Mar 14 '22 18:03 atishpatel

Overall LGTM, but let's move it into a separate package, perhaps helpwriter.

alecthomas avatar Mar 21 '22 07:03 alecthomas

Ping on last comment?

alecthomas avatar Apr 10 '22 05:04 alecthomas

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.

atishpatel avatar Apr 10 '22 08:04 atishpatel

All good, no hurry :)

alecthomas avatar Apr 10 '22 08:04 alecthomas

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?

atishpatel avatar May 06 '22 21:05 atishpatel

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.

atishpatel avatar May 06 '22 21:05 atishpatel

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. 🤞

atishpatel avatar May 06 '22 22:05 atishpatel

Any news on this? I'm assuming this would help solve https://github.com/alecthomas/kong/issues/33?

EDIT: Commented on a workaround here.

Dids avatar Aug 07 '22 09:08 Dids