poafloc

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

commit 4f7bad5dac5683710d20921ed4b00eee7f1137a7
parent 4a5bf21bf3d47c94020a12a43ab2c7fb3094be87
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  7 Jun 2024 21:19:31 +0200

Long messages are now split into multiple lines

Diffstat:
Margs.hpp | 25++++++++++++++++++++-----
Mdemo.cpp | 4++--
2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/args.hpp b/args.hpp @@ -7,6 +7,7 @@ #include <exception> #include <format> #include <iostream> +#include <sstream> #include <unordered_map> #include <vector> @@ -76,18 +77,20 @@ class Parser { if ((opt.options & ALIAS) == 0) { help_entries.emplace_back(opt.arg, opt.message); - if (std::isprint(opt.key)) - help_entries.back().push(opt.key); if (opt.name) help_entries.back().push(opt.name); + if (std::isprint(opt.key)) { + help_entries.back().push(opt.key); + } } else { if (!key_last) { std::cerr << "no option to alias\n"; throw new std::runtime_error("no alias"); } - if (std::isprint(opt.key)) - help_entries.back().push(opt.key); if (opt.name) help_entries.back().push(opt.name); + if (std::isprint(opt.key)) { + help_entries.back().push(opt.key); + } } } @@ -325,7 +328,19 @@ class Parser { if (count < limit) std::cout << std::string(limit - count, ' '); if (entry.message()) { - std::cout << std::format(" {}", entry.message()); + std::istringstream iss(entry.message()); + std::size_t count = 0; + std::string s; + + std::cout << " "; + while (iss >> s) { + count += size(s); + if (count > limit) { + std::cout << std::endl << std::string(limit + 5, ' '); + count = size(s); + } + std::cout << s << " "; + } } std::cout << std::endl; } diff --git a/demo.cpp b/demo.cpp @@ -31,7 +31,7 @@ int parse_opt(int key, const char *arg, void *input) { case 'o': arguments->output_file = arg ? arg : "stdout"; break; case 'i': arguments->input_file = arg; break; case Parser::Key::ARG: arguments->args.push_back(arg); break; - case Parser::Key::ERROR: std::cerr << "handled error\n"; + case Parser::Key::ERROR: std::cerr << "handled error\n"; } return 0; @@ -42,7 +42,7 @@ 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"}, + { 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},