Thoughts on the new Help customization framework
Created by: dregad
In 3.0, the library allows 2 methods to customize the output of getHelpText:
- via a class implementing GetOpt\HelpInterface, or
- by writing custom template scripts, similar to those provided in resources/
I hope you won't mind my saying so, but I'm not very keen on the proposed approach, particularly the second one, and I think this should be improved. Here's a few issues I see:
- having to create up to 3 custom templates (even as copies of the provided ones) and maintain them is cumbersome
- there is some code and logic in the original templates which would be nice to be able to reuse as-is in custom ones
- Some of this logic is duplicated (e.g. the console width detection is both in options.php and commands.php
- let's say I want to keep the standard template, but localize the output; I can't do that easily because some strings are hardcoded
The custom Help class is better, but still does not allow easy reuse of code in the default templates.
A couple of suggestions for improvement:
- instead of relying on standalone PHP scripts for templates and using output buffering to capture their output, let the setXxxTemplate() methods accept a callable instead, and put the contents of the script into methods of the Help class which will return a string instead of echoing.
- extract duplicated code into helper methods, to be used as building bricks for the callable
- provide a way to localize the output
Let me know your thoughts.