mirror of https://github.com/djcb/mu.git
cli: merge 'fields' with 'info' command
Update the 'info' command to handle 'fields' as well; remove fields.
This commit is contained in:
parent
5e184a581f
commit
9004363aa5
5
NEWS.org
5
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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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)*
|
|
@ -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 [<topic>]*
|
||||
|
||||
* 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)*
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** 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 <iostream>
|
||||
#include <functional>
|
||||
|
||||
#include "mu-cmd.hh"
|
||||
#include <message/mu-message.hh>
|
||||
#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<void>
|
||||
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();
|
||||
|
||||
}
|
|
@ -18,21 +18,123 @@
|
|||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mu-cmd.hh"
|
||||
#include <message/mu-message.hh>
|
||||
#include "utils/mu-utils.hh"
|
||||
|
||||
#include <thirdparty/tabulate.hpp>
|
||||
|
||||
using namespace Mu;
|
||||
using namespace tabulate;
|
||||
|
||||
Result<void>
|
||||
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<void>
|
||||
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<void>
|
||||
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) {
|
||||
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';
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static void
|
||||
colorify(Table& table)
|
||||
{
|
||||
for (auto&& row: table) {
|
||||
|
||||
if (row.cells().size() < 2)
|
||||
|
@ -42,7 +144,13 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts)
|
|||
.font_color(Color::green);
|
||||
row.cells().at(1)->format().font_color(Color::blue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
static Result<void>
|
||||
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<void>
|
||||
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<void>
|
||||
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 <topic>'):\n"
|
||||
<< topic("store") << " - information about the message store (database)\n"
|
||||
<< topic("fields") << " - information about message fields\n";
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
|
13
mu/mu-cmd.cc
13
mu/mu-cmd.cc
|
@ -43,6 +43,17 @@
|
|||
|
||||
using namespace Mu;
|
||||
|
||||
|
||||
static Result<void>
|
||||
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<void>
|
||||
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:
|
||||
|
|
|
@ -79,15 +79,6 @@ Result<void> mu_cmd_cfind(const Store& store, const Options& opts);
|
|||
*/
|
||||
Result<void> mu_cmd_extract(const Options& opts);
|
||||
|
||||
/**
|
||||
* execute the 'fields' command
|
||||
*
|
||||
* @param opts configuration options
|
||||
*
|
||||
* @return Ok() or some error
|
||||
*/
|
||||
Result<void> mu_cmd_fields(const Options& opts);
|
||||
|
||||
/**
|
||||
* execute the 'find' command
|
||||
*
|
||||
|
|
|
@ -359,7 +359,6 @@ sub_help(CLI::App& sub, Options& opts)
|
|||
->type_name("<command>");
|
||||
}
|
||||
|
||||
|
||||
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("<topic>") ;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -512,7 +513,7 @@ AssocPairs<SubCommand, CommandInfo, Options::SubCommandNum> 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,
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
/* command-line options for Mu */
|
||||
namespace Mu {
|
||||
struct Options {
|
||||
|
||||
using OptSize = Option<std::size_t>;
|
||||
using SizeVec = std::vector<std::size_t>;
|
||||
using OptTStamp = Option<std::time_t>;
|
||||
|
@ -177,6 +176,9 @@ struct Options {
|
|||
/*
|
||||
* Info
|
||||
*/
|
||||
struct Info {
|
||||
std::string topic; /**< what to get info about? */
|
||||
} info;
|
||||
|
||||
/*
|
||||
* Init
|
||||
|
|
Loading…
Reference in New Issue