mu: implement new command-line parser

Implement a new command-line parser, based on CLI11.

It's a bit more C++'ish, and allows for a lot of fancy things... some of
which we have implemented here.

Update the various commands to use the new Options struct

Remove the old help strings; instead e.g. `mu help view` opens the
manpage.

Integrate the guile scripts more tightly.
This commit is contained in:
Dirk-Jan C. Binnema
2022-11-16 22:51:15 +02:00
parent 27a474be41
commit 36f6e387ae
16 changed files with 1439 additions and 1857 deletions

View File

@ -30,9 +30,9 @@ using namespace tabulate;
static void
table_header(Table& table, const MuConfig* opts)
table_header(Table& table, const Options& opts)
{
if (opts->nocolor)
if (opts.nocolor)
return;
(*table.begin()).format()
@ -42,7 +42,7 @@ table_header(Table& table, const MuConfig* opts)
}
static void
show_fields(const MuConfig* opts)
show_fields(const Options& opts)
{
using namespace std::string_literals;
@ -54,7 +54,7 @@ show_fields(const MuConfig* opts)
if (sv.empty())
return "";
else
return format("%*s", STR_V(sv));
return format("%.*s", STR_V(sv));
};
auto searchable=[&](const Field& field)->std::string {
@ -76,8 +76,8 @@ show_fields(const MuConfig* opts)
if (field.is_internal())
return; // skip.
fields.add_row({format("%*s", STR_V(field.name)),
field.alias.empty() ? "" : format("%*s", STR_V(field.alias)),
fields.add_row({format("%.*s", STR_V(field.name)),
field.alias.empty() ? "" : format("%.*s", STR_V(field.alias)),
field.shortcut ? format("%c", field.shortcut) : ""s,
searchable(field),
field.is_value() ? "yes" : "no",
@ -93,7 +93,7 @@ show_fields(const MuConfig* opts)
}
static void
show_flags(const MuConfig* opts)
show_flags(const Options& opts)
{
using namespace tabulate;
using namespace std::string_literals;
@ -119,7 +119,7 @@ show_flags(const MuConfig* opts)
}
}, info.category);
flags.add_row({format("%*s", STR_V(info.name)),
flags.add_row({format("%.*s", STR_V(info.name)),
format("%c", info.shortcut),
catname,
std::string{info.description}});
@ -133,14 +133,11 @@ show_flags(const MuConfig* opts)
Result<void>
Mu::mu_cmd_fields(const MuConfig* opts)
Mu::mu_cmd_fields(const Options& opts)
{
g_return_val_if_fail(opts, Err(Error::Code::Internal, "no opts"));
if (!locale_workaround())
return Err(Error::Code::User, "failed to find a working locale");
std::cout << "#\n# message fields\n#\n";
show_fields(opts);
std::cout << "\n#\n# message flags\n#\n";