poafloc

poafloc - Parser Of Arguments For Lines Of Commands
git clone git://git.dimitrijedobrota.com/poafloc.git
Log | Files | Refs | README | LICENSE

commit 3cdb743888aa56c5e5301858e24973284a311946
parent 0ab5aaf2158b43e4fa1423450384ed51a6c9cbd2
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat,  8 Jun 2024 22:05:12 +0200

Add support for 2 part message in --help

Diffstat:
Margs.hpp | 11+++++++++++
Mdemo.cpp | 7++++++-
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/args.hpp b/args.hpp @@ -42,6 +42,7 @@ class Parser { const option_t *options; const parse_f parser; const char *doc; + const char *message; }; Parser(argp_t *argp) : argp(argp) { @@ -318,8 +319,16 @@ class Parser { } void help(const char *name) const { + std::string m1, m2; + if (argp->message) { + std::istringstream iss(argp->message); + std::getline(iss, m1, '\v'); + std::getline(iss, m2, '\v'); + } + std::cout << std::format("Usage: {} [OPTIONS...]", name); print_usage(name); + if (!m1.empty()) std::cout << "\n" << m1; std::cout << "\n\n"; for (const auto &entry : help_entries) { @@ -377,6 +386,8 @@ class Parser { std::cout << std::endl; } + if (!m2.empty()) std::cout << "\n" << m2 << "\n"; + exit(0); } diff --git a/demo.cpp b/demo.cpp @@ -52,7 +52,12 @@ static const Parser::option_t options[] = { // clang-format on int main(int argc, char *argv[]) { - Parser::argp_t argp = {options, parse_opt, "doc string"}; + Parser::argp_t argp = { + options, + parse_opt, + "doc string\nother usage", + "First half of the message\vsecond half of the message" + }; Parser parser(&argp); arguments_t arguments;