poafloc

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

commitf43244f45b0a1d518bafd73e85555c25bacb02a0
parent84921ee22706704d4d37b23fe3341a0218d099d0
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSat, 8 Jun 2024 19:00:24 +0200

Exclude options with HIDDEN flag from --help

Diffstat:
Margs.hpp|++++++++++++-----
Mdemo.cpp|++++++------

2 files changed, 18 insertions(+), 11 deletions(-)


diff --git a/args.hpp b/args.hpp

@@ -45,10 +45,10 @@ class Parser {

};
Parser(argp_t *argp) : argp(argp) {
int key_last;
int i = 0;
bool hidden = false;
int key_last = 0;
while (true) {
for (int i = 0; true; i++) {
const auto &opt = argp->options[i];
if (!opt.name && !opt.key) break;

@@ -64,6 +64,10 @@ class Parser {

}
trie.insert(opt.name, key_last);
if (hidden) continue;
if (opt.options & Option::HIDDEN) continue;
help_entries.back().push(opt.name);
} else {
if (options.count(opt.key)) {

@@ -77,6 +81,8 @@ class Parser {

bool arg_opt = opt.options & Option::ARG_OPTIONAL;
if ((opt.options & ALIAS) == 0) {
if ((hidden = opt.options & Option::HIDDEN)) continue;
help_entries.emplace_back(opt.arg, opt.message, arg_opt);
if (opt.name) help_entries.back().push(opt.name);

@@ -89,14 +95,15 @@ class Parser {

throw new std::runtime_error("no alias");
}
if (hidden) continue;
if (opt.options & Option::HIDDEN) continue;
if (opt.name) help_entries.back().push(opt.name);
if (std::isprint(opt.key)) {
help_entries.back().push(opt.key);
}
}
}
i++;
}
std::sort(begin(help_entries), end(help_entries));

diff --git a/demo.cpp b/demo.cpp

@@ -41,12 +41,12 @@ using enum Parser::Option;

// clang-format off
static const Parser::option_t options[] = {
{ "output", 'o', "file", ARG_OPTIONAL, "Output file, default stdout"},
{ 0, 'i', "file", 0, "Input file"},
{ "debug", 777, 0, 0, "Execute program in debugging mode"},
{ "hex", 'h', 0, 0, "Output in hex format"},
{"hexadecimal", 0, 0, ALIAS},
{"relocatable", 'r', 0, 0, "Output in relocatable format"},
{ "output", 'o', "file", ARG_OPTIONAL, "Output file, default stdout"},
{ 0, 'i', "file", 0, "Input file"},
{ "debug", 777, 0, 0, "Execute program in debugging mode"},
{ "hex", 'h', 0, 0, "Output in hex format"},
{"hexadecimal", 0, 0, ALIAS | HIDDEN},
{"relocatable", 'r', 0, 0, "Output in relocatable format"},
{0},
};
// clang-format on