8000 any detail::format_help() alternatives? · Issue #1153 · CLIUtils/CLI11 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

any detail::format_help() alternatives? #1153

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

Closed
leaveye opened this issue Apr 25, 2025 · 1 comment
Closed

any detail::format_help() alternatives? #1153

leaveye opened this issue Apr 25, 2025 · 1 comment

Comments

@leaveye
Copy link
leaveye commented Apr 25, 2025

i was using CLI11::detail::format_help() function to make help footer like this:

<command help message before...>

Environment Variables:
  CONF_CS_HOST [127.0.0.1]    ConfSet database host
  CONF_CS_PORT [1902]         ConfSet database port
  DUMP_HEX_COLUMNS [32]       Data dump columns
  CONF_LOG_NAME [log.conf]    LOG config file basename
  CONF_LOG_PATH [.:..:/etc/${PROCNAME}:/etc]
                              LOG config search path list

Copyright blahblah.

by write a simply helper function:

string make_option_help(CLI::App_p app, const string &name, const string &desc, const string &default_) {
    std::stringstream out;
    auto name_part = name;
    auto &description = desc;
    if (!default_.empty()) name_part = name_part + " [" + default_ + "]";
    CLI::detail::format_help(out,
                             name_part,
                             description,
                             app->get_formatter()->get_column_width());
    return out.str();
}

CLI::App_p add_footer(CLI::App_p app, const string &text) {
    std::stringstream out;
    out << app->get_footer();
    out << text;
    app->footer(out.str());
    return app;
}

#define make_environ_help(APP, VAR, DESC) make_option_help(APP, #VAR, DESC, VAR)
#define add_environ_help(APP, VAR, DESC) add_footer(APP, make_option_help(APP, #VAR, DESC, VAR))

with calling like:

#define CONF_CS_HOST "127.0.0.1"
#define CONF_CS_PORT "1902"
#define DUMP_HEX_COLUMNS "32"

    add_environ_help(app, CONF_CS_HOST, "ConfSet database host");
    add_environ_help(app, CONF_CS_PORT, "ConfSet database port");
    add_environ_help(app, DUMP_HEX_COLUMNS, "Data dump columns");

while detail::format_help() is removed in the v2.5.0, is there any helper to do this formatting?

@phlptp
Copy link
Collaborator
phlptp commented Apr 27, 2025

The formatter object can be subclassed to do all sorts of things. See #1145 for some discussion on this. There is a formatter.cpp example as well that does this.

@phlptp phlptp closed this as completed Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0