poafloc

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

commit 0ab5aaf2158b43e4fa1423450384ed51a6c9cbd2
parent 9c58f374dcc4ea758cb933a9bc409cc8a398dc6f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat,  8 Jun 2024 22:04:01 +0200

Add support for coding multiple usages in doc

Diffstat:
Margs.hpp | 22+++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/args.hpp b/args.hpp @@ -302,9 +302,25 @@ class Parser { } }; + void print_usage(const char *name) const { + if (argp->doc) { + std::istringstream iss(argp->doc); + std::string s; + + std::getline(iss, s, '\n'); + std::cout << " " << s; + + while (std::getline(iss, s, '\n')) { + std::cout << std::format("\n or: {} [OPTIONS...] {}", name, + s); + } + } + } + void help(const char *name) const { - std::cout << std::format("Usage: {} [OPTIONS...] {}\n\n", name, - argp->doc ? argp->doc : ""); + std::cout << std::format("Usage: {} [OPTIONS...]", name); + print_usage(name); + std::cout << "\n\n"; for (const auto &entry : help_entries) { bool prev = false; @@ -414,7 +430,7 @@ class Parser { } } - if (argp->doc) print(argp->doc); + print_usage(name); std::cout << std::endl; exit(0);