diff --git a/NEWS.org b/NEWS.org index e1b63fd6..c4c3b9e1 100644 --- a/NEWS.org +++ b/NEWS.org @@ -16,6 +16,9 @@ an e-mail corpus, so it useful to get rid of those, with '=--ignored-address=/.*noreply*/'= + - what used to be the ~mu fields~ command has been merged into ~mu info~; i.e., + ~mu fields~ is now ~mu info fields~. + - experimental: if you build ~mu~ with [[https://github.com/CLD2Owners/cld2][CLD2]] support (available in many Linux distros), ~mu~ will try to detect the language of the body of e-mail messages; you can then search by their ISO-639-1 code, e.g. ~mu find @@ -49,7 +52,7 @@ details. - The ~init~ command learned ~--reinit~ to reinitialize the database with the - setings of an existing one + settings of an existing one - The ~script~ command is gone, and integrated with ~mu~ directly, i.e. the scripts (when enabled) are directly visible in the ~mu~ output. Also see the diff --git a/man/meson.build b/man/meson.build index e498c926..d0ae3ee7 100644 --- a/man/meson.build +++ b/man/meson.build @@ -50,7 +50,6 @@ man_orgs=[ 'mu-cfind.1.org', 'mu-easy.7.org', 'mu-extract.1.org', - 'mu-fields.1.org', 'mu-find.1.org', 'mu-help.1.org', 'mu-index.1.org', diff --git a/man/mu-fields.1.org b/man/mu-fields.1.org deleted file mode 100644 index 9b4179f2..00000000 --- a/man/mu-fields.1.org +++ /dev/null @@ -1,24 +0,0 @@ -#+TITLE: MU FIELDS -#+MAN_CLASS_OPTIONS: :section-id "@SECTION_ID@" :date "@MAN_DATE@" - - -* NAME - -*mu fields* - list all message fields - -* SYNOPSIS - -*mu [common-options] fields - -* DESCRIPTION - -*mu fields* is the *mu* command for showing a table of message fields and their -properties. - -#+include: "common-options.inc" :minlevel 1 - -#+include: "prefooter.inc" :minlevel 1 - -* SEE ALSO - -*mu(1)* diff --git a/man/mu-info.1.org b/man/mu-info.1.org index 5e0b3f92..c9307685 100644 --- a/man/mu-info.1.org +++ b/man/mu-info.1.org @@ -3,15 +3,21 @@ * NAME -~mu info~ - show information about the mu database +~mu info~ - show information * SYNOPSIS -*mu [common options] info* +*mu [common options] info []* * DESCRIPTION -~mu info~ is the ~mu~ command for getting information about the mu database. Note +~mu info~ is the ~mu~ command for getting information about various topics: + +- *common*: general mu build information +- *store*: information about the message store +- *fields*: table with all the query fields and flags + +about the mu database. Note that while running (e.g. ~mu4e~), some of the information may be slightly delayed due to database caching. @@ -23,4 +29,4 @@ due to database caching. * SEE ALSO -*maildir(5)*, *mu(1)* +*mu(1)* diff --git a/mu/meson.build b/mu/meson.build index 7a33259b..7871ec49 100644 --- a/mu/meson.build +++ b/mu/meson.build @@ -21,7 +21,6 @@ mu = executable( 'mu-cmd-add.cc', 'mu-cmd-cfind.cc', 'mu-cmd-extract.cc', - 'mu-cmd-fields.cc', 'mu-cmd-find.cc', 'mu-cmd-info.cc', 'mu-cmd-init.cc', diff --git a/mu/mu-cmd-fields.cc b/mu/mu-cmd-fields.cc deleted file mode 100644 index f92ff1fe..00000000 --- a/mu/mu-cmd-fields.cc +++ /dev/null @@ -1,148 +0,0 @@ -/* -** Copyright (C) 2022 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it under -** the terms of the GNU General Public License as published by the Free Software -** Foundation; either version 3, or (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, but WITHOUT -** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -** details. -** -** You should have received a copy of the GNU General Public License along with -** this program; if not, write to the Free Software Foundation, Inc., 51 -** Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ -#include -#include - -#include "mu-cmd.hh" -#include -#include "utils/mu-utils.hh" - -#include "thirdparty/tabulate.hpp" - - -using namespace Mu; -using namespace tabulate; - - -static void -table_header(Table& table, const Options& opts) -{ - if (opts.nocolor) - return; - - (*table.begin()).format() - .font_style({FontStyle::bold}) - .font_color(Color::blue); - -} - -static void -show_fields(const Options& opts) -{ - using namespace std::string_literals; - - Table fields; - fields.add_row({"field-name", "alias", "short", "search", - "value", "sexp", "example query", "description"}); - - auto disp= [&](std::string_view sv)->std::string { - if (sv.empty()) - return ""; - else - return format("%.*s", STR_V(sv)); - }; - - auto searchable=[&](const Field& field)->std::string { - if (field.is_boolean_term()) - return "boolean"; - if (field.is_indexable_term()) - return "index"; - if (field.is_normal_term()) - return "yes"; - if (field.is_contact()) - return "contact"; - if (field.is_range()) - return "range"; - return "no"; - }; - - size_t row{}; - field_for_each([&](auto&& field){ - if (field.is_internal()) - return; // skip. - - 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", - field.include_in_sexp() ? "yes" : "no", - disp(field.example_query), - disp(field.description)}); - ++row; - }); - - table_header(fields, opts); - - std::cout << fields << '\n'; -} - -static void -show_flags(const Options& opts) -{ - using namespace tabulate; - using namespace std::string_literals; - - Table flags; - flags.add_row({"flag", "shortcut", "category", "description"}); - - flag_infos_for_each([&](const MessageFlagInfo& info) { - - const auto catname = std::invoke( - [](MessageFlagCategory cat)->std::string { - switch(cat){ - case MessageFlagCategory::Mailfile: - return "file"; - case MessageFlagCategory::Maildir: - return "maildir"; - case MessageFlagCategory::Content: - return "content"; - case MessageFlagCategory::Pseudo: - return "pseudo"; - default: - return {}; - } - }, info.category); - - flags.add_row({format("%.*s", STR_V(info.name)), - format("%c", info.shortcut), - catname, - std::string{info.description}}); - }); - - table_header(flags, opts); - - std::cout << flags << '\n'; -} - - - -Result -Mu::mu_cmd_fields(const Options& 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"; - show_flags(opts); - - return Ok(); - -} diff --git a/mu/mu-cmd-info.cc b/mu/mu-cmd-info.cc index 60095f56..bc94086f 100644 --- a/mu/mu-cmd-info.cc +++ b/mu/mu-cmd-info.cc @@ -18,31 +18,139 @@ */ #include "config.h" + #include "mu-cmd.hh" +#include +#include "utils/mu-utils.hh" #include using namespace Mu; +using namespace tabulate; -Result -Mu::mu_cmd_info(const Mu::Store& store, const Options& opts) +static void +table_header(Table& table, const Options& opts) +{ + if (opts.nocolor) + return; + + (*table.begin()).format() + .font_style({FontStyle::bold}) + .font_color(Color::blue); + +} + +static Result +topic_fields(const Options& opts) +{ + using namespace std::string_literals; + + Table fields; + fields.add_row({"field-name", "alias", "short", "search", + "value", "sexp", "example query", "description"}); + + auto disp= [&](std::string_view sv)->std::string { + if (sv.empty()) + return ""; + else + return format("%.*s", STR_V(sv)); + }; + + auto searchable=[&](const Field& field)->std::string { + if (field.is_boolean_term()) + return "boolean"; + if (field.is_indexable_term()) + return "index"; + if (field.is_normal_term()) + return "yes"; + if (field.is_contact()) + return "contact"; + if (field.is_range()) + return "range"; + return "no"; + }; + + size_t row{}; + field_for_each([&](auto&& field){ + if (field.is_internal()) + return; // skip. + + 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", + field.include_in_sexp() ? "yes" : "no", + disp(field.example_query), + disp(field.description)}); + ++row; + }); + + table_header(fields, opts); + + std::cout << fields << '\n'; + + return Ok(); +} + +static Result +topic_flags(const Options& opts) { using namespace tabulate; + using namespace std::string_literals; - if (!locale_workaround()) - return Err(Error::Code::User, "failed to find a working locale"); + Table flags; + flags.add_row({"flag", "shortcut", "category", "description"}); - auto colorify = [](Table& table) { - for (auto&& row: table) { + flag_infos_for_each([&](const MessageFlagInfo& info) { - if (row.cells().size() < 2) - continue; + const auto catname = std::invoke( + [](MessageFlagCategory cat)->std::string { + switch(cat){ + case MessageFlagCategory::Mailfile: + return "file"; + case MessageFlagCategory::Maildir: + return "maildir"; + case MessageFlagCategory::Content: + return "content"; + case MessageFlagCategory::Pseudo: + return "pseudo"; + default: + return {}; + } + }, info.category); - row.cells().at(0)->format().font_style({FontStyle::bold}) - .font_color(Color::green); - row.cells().at(1)->format().font_color(Color::blue); - } - }; + flags.add_row({format("%.*s", STR_V(info.name)), + format("%c", info.shortcut), + catname, + std::string{info.description}}); + }); + + table_header(flags, opts); + + std::cout << flags << '\n'; + return Ok(); +} + +static void +colorify(Table& table) +{ + for (auto&& row: table) { + + if (row.cells().size() < 2) + continue; + + row.cells().at(0)->format().font_style({FontStyle::bold}) + .font_color(Color::green); + row.cells().at(1)->format().font_color(Color::blue); + } +} + + +static Result +topic_store(const Mu::Store& store, const Options& opts) +{ + using namespace tabulate; auto tstamp = [](::time_t t)->std::string { if (t == 0) @@ -77,3 +185,76 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts) return Ok(); } + +static Result +topic_common(const Options& opts) +{ + Table info; + + using namespace tabulate; + + info.add_row({"mu version", std::string{VERSION}}); + info.add_row({"store schema-version", format("%u", MU_STORE_SCHEMA_VERSION)}); + info.add_row({"guile-support:", +#if BUILD_GUILE + "yes" +#else + "no" +#endif + }); + info.add_row({"readline-support:", +#if HAVE_LIBREADLINE + "yes" +#else + "no" +#endif + }); + + info.add_row({"cld2 language support:", +#if HAVE_CLD2 + "yes" +#else + "no" +#endif + }); + + if (!opts.nocolor) + colorify(info); + + std::cout << info << '\n'; + + return Ok(); +} + + +Result +Mu::mu_cmd_info(const Mu::Store& store, const Options& opts) +{ + if (!locale_workaround()) + return Err(Error::Code::User, "failed to find a working locale"); + + const auto topic{opts.info.topic}; + if (topic == "store") + return topic_store(store, opts); + else if (topic == "fields") { + topic_fields(opts); + return topic_flags(opts); + } else if (topic == "common") { + return topic_common(opts); + } else { + topic_common(opts); + + MaybeAnsi col{!opts.nocolor}; + using Color = MaybeAnsi::Color; + + auto topic = [&](const std::string& s)->std::string { + return " " + col.fg(Color::Green) + s.c_str() + col.reset(); + }; + + std::cout << "\nother available info topics ('mu info '):\n" + << topic("store") << " - information about the message store (database)\n" + << topic("fields") << " - information about message fields\n"; + } + + return Ok(); +} diff --git a/mu/mu-cmd.cc b/mu/mu-cmd.cc index f39c2845..52d7ced7 100644 --- a/mu/mu-cmd.cc +++ b/mu/mu-cmd.cc @@ -43,6 +43,17 @@ using namespace Mu; + +static Result +cmd_fields(const Options& opts) +{ + g_printerr("the 'mu fields' command has been superseded by 'mu info'; try:\n" + " mu info fields\n" + " mu info flags\n"); + + return Ok(); +} + static Result cmd_find(const Options& opts) { @@ -101,7 +112,7 @@ Mu::mu_cmd_execute(const Options& opts) try { * no store needed */ case Options::SubCommand::Fields: - return mu_cmd_fields(opts); + return cmd_fields(opts); case Options::SubCommand::Mkdir: return mu_cmd_mkdir(opts); case Options::SubCommand::Script: diff --git a/mu/mu-cmd.hh b/mu/mu-cmd.hh index 9fcfa9ae..980806db 100644 --- a/mu/mu-cmd.hh +++ b/mu/mu-cmd.hh @@ -79,15 +79,6 @@ Result mu_cmd_cfind(const Store& store, const Options& opts); */ Result mu_cmd_extract(const Options& opts); -/** - * execute the 'fields' command - * - * @param opts configuration options - * - * @return Ok() or some error - */ -Result mu_cmd_fields(const Options& opts); - /** * execute the 'find' command * diff --git a/mu/mu-options.cc b/mu/mu-options.cc index 0d466649..150b50af 100644 --- a/mu/mu-options.cc +++ b/mu/mu-options.cc @@ -359,7 +359,6 @@ sub_help(CLI::App& sub, Options& opts) ->type_name(""); } - static void sub_index(CLI::App& sub, Options& opts) { @@ -373,7 +372,9 @@ sub_index(CLI::App& sub, Options& opts) static void sub_info(CLI::App& sub, Options& opts) { - // nothing to do. + sub.add_option("topic", opts.info.topic, + "Information topic") + ->type_name("") ; } static void @@ -512,7 +513,7 @@ AssocPairs SubCommandInfos= {{ }, { SubCommand::Fields, {Category::None, - "fields", "Show a information about search fields", sub_fields} + "fields", "Superseded by 'mu info'", sub_fields} }, { SubCommand::Find, {Category::NeedsReadOnlyStore, diff --git a/mu/mu-options.hh b/mu/mu-options.hh index 8b399acf..9adfbcbd 100644 --- a/mu/mu-options.hh +++ b/mu/mu-options.hh @@ -36,7 +36,6 @@ /* command-line options for Mu */ namespace Mu { struct Options { - using OptSize = Option; using SizeVec = std::vector; using OptTStamp = Option; @@ -177,6 +176,9 @@ struct Options { /* * Info */ + struct Info { + std::string topic; /**< what to get info about? */ + } info; /* * Init