Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an extra class Help or HelpProvider. #108

Closed
henryiii opened this issue Apr 14, 2018 · 4 comments
Closed

Add an extra class Help or HelpProvider. #108

henryiii opened this issue Apr 14, 2018 · 4 comments
Milestone

Comments

@henryiii
Copy link
Collaborator

henryiii commented Apr 14, 2018

This would allow customization of all components of the help messages; things like localization would be possible.

I like the idea of adding a new class that takes responsibility for the help formatting; even with no changes, this would keep App and Option a bit shorter and cleaner, which is a good thing.

@henryiii
Copy link
Collaborator Author

henryiii commented Apr 14, 2018

Idea 1:

Provide a virtual class that users could customize.

class HelpFormatter {
    std::string REQUIRED = "Required";
    
    virtual std::string help_name(Option* opt) {...}
    virtual std::string help_opts(Option* opt) {...}
    virtual std::string help_desc(Option* opt) {...}
    virtual std::string combine_help(Option* opt) {...}

    virtual std::string make_group(App* app, std::string name) {...}
    virtual std::string make_description(App* app) {...}
    virtual std::string make_usage(App* app, std::string name) {...}

    virtual std::string make_help(App* app) {...}
    virtual std::string make_help_all(App* app) {...} // NEW, exapands groups
}

The standard combine help would do:

help_name help_opts
     <space as needed>  help_desc
     <wrap/indent as needed>

Hooks could be added for the rest of the formatting, as well, like group names.

You would use it like this:

class MyHelp : public HelpFormatter {...}

app.set_help_formatter(MyHelp());

It would then be inherited by subcommands. Subclasses of App would also be able to change the default help formatter.

@henryiii
Copy link
Collaborator Author

Idea 2:

Add a class that accepts lambda functions (as std::function pointers) and variables. Then you would do:

app.get_help_formatter().set_required_name("(REQUIRED)");
app.get_help_formatter().set_combine_help([](...){...});

@henryiii
Copy link
Collaborator Author

Idea 3:

Add a template formatting language.

@lczech
Copy link
Collaborator

lczech commented Apr 18, 2018

Thanks for putting together this issue!

Here are some thoughts on what would be nice to have (copied from the gitter chat):

  • Customize all formatting, spaces, text highlighting etc. This is basically already possible with any of the above design ideas.
  • Customize the static texts, e.g., type names like UINT, the "REQUIRED" text, "Usage: ..." etc. If those can be customized, i18n/l10n would be easier/possible.
  • Long term: Have validators generate their own help text, e.g., the Range can output in [0.0, 1.0] or the like, and files and paths could output FILE instead of TEXT.

@henryiii henryiii mentioned this issue Apr 24, 2018
11 tasks
@henryiii henryiii added this to the v1.6 milestone May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants