poafloc

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

commit 8f23f3e512d0d0ea9570d3a424522215cc3300f9
parent 8e2a644beab494ee756bec5c5bdb8aa73541c361
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat,  8 Jun 2024 21:30:55 +0200

Get rid of unnecessary indent

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

diff --git a/args.hpp b/args.hpp @@ -315,13 +315,11 @@ class Parser { else message += ", "; message += std::format("-{}", c); - if (entry.arg && entry.opt_long.empty()) { - if (entry.opt) { - message += std::format("[{}]", entry.arg); - } else { - message += std::format(" {}", entry.arg); - } - } + + if (!entry.arg || !entry.opt_long.empty()) continue; + + if (entry.opt) message += std::format("[{}]", entry.arg); + else message += std::format(" {}", entry.arg); } if (!prev) message += " "; @@ -331,13 +329,11 @@ class Parser { else message += ", "; message += std::format("--{}", l); - if (entry.arg) { - if (entry.opt) { - message += std::format("[={}]", entry.arg); - } else { - message += std::format("={}", entry.arg); - } - } + + if (!entry.arg) continue; + + if (entry.opt) message += std::format("[={}]", entry.arg); + else message += std::format("={}", entry.arg); } static const std::size_t limit = 30; @@ -398,11 +394,8 @@ class Parser { for (const auto &entry : help_entries) { if (!entry.arg) continue; for (const char c : entry.opt_short) { - if (entry.opt) { - print(std::format(" [-{}[{}]]", c, entry.arg)); - } else { - print(std::format(" [-{} {}]", c, entry.arg)); - } + if (entry.opt) print(std::format(" [-{}[{}]]", c, entry.arg)); + else print(std::format(" [-{} {}]", c, entry.arg)); } }