mu: merge flags into fields command

One is enough
pull/2234/merge
Dirk-Jan C. Binnema 9 months ago
parent 0112180bcb
commit f9550f3cb6
  1. 2
      lib/message/mu-fields.hh
  2. 67
      mu/mu-cmd-fields.cc
  3. 7
      mu/mu-cmd.cc
  4. 11
      mu/mu-cmd.hh
  5. 2
      mu/mu-config.cc
  6. 1
      mu/mu-config.hh

@ -249,7 +249,7 @@ static constexpr std::array<Field, Field::id_size()>
Field::Type::TimeT,
"changed", {},
"Last change time",
"change:30m..now",
"changed:30M..",
'k',
Field::Flag::Value |
Field::Flag::Range |

@ -15,32 +15,41 @@
** Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#include <iostream>
#include <functional>
#include "mu-cmd.hh"
#include <message/mu-message.hh>
#include <iostream>
#include "mu-flags.hh"
#include "utils/mu-utils.hh"
#include "thirdparty/tabulate.hpp"
using namespace Mu;
using namespace tabulate;
static void
table_header(Table& table, const MuConfig* opts)
{
if (opts->nocolor)
return;
(*table.begin()).format()
.font_style({FontStyle::bold})
.font_color({Color::blue});
}
static void
show_fields(const MuConfig* opts)
{
using namespace tabulate;
using namespace std::string_literals;
Table fields;
fields.add_row({"field-name", "alias", "short", "search",
"value", "example", "description"});
if (!opts->nocolor) {
(*fields.begin()).format()
.font_style({FontStyle::bold})
.font_color({Color::blue});
}
auto disp= [&](std::string_view sv)->std::string {
if (sv.empty())
return "";
@ -77,6 +86,8 @@ show_fields(const MuConfig* opts)
++row;
});
table_header(fields, opts);
std::cout << fields << '\n';
}
@ -89,20 +100,32 @@ show_flags(const MuConfig* opts)
Table flags;
flags.add_row({"flag", "shortcut", "category", "description"});
if (!opts->nocolor) {
(*flags.begin()).format()
.font_style({FontStyle::bold})
.font_color({Color::green});
}
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),
"<cat>"s,
catname,
std::string{info.description}});
});
table_header(flags, opts);
std::cout << flags << '\n';
}
@ -113,17 +136,9 @@ Mu::mu_cmd_fields(const MuConfig* opts)
{
g_return_val_if_fail(opts, Err(Error::Code::Internal, "no opts"));
std::cout << "#\n# message fields\n#\n";
show_fields(opts);
return Ok();
}
Result<void>
Mu::mu_cmd_flags(const MuConfig* opts)
{
g_return_val_if_fail(opts, Err(Error::Code::Internal, "no opts"));
std::cout << "\n#\n# message flags\n#\n";
show_flags(opts);
return Ok();

@ -615,11 +615,11 @@ Mu::mu_cmd_execute(const MuConfig* opts, GError** err) try {
if (!check_params(opts, err))
return MU_G_ERROR_CODE(err);
auto mu_error_from_result = [](auto&& result, GError **err) {
auto mu_error_from_result = [](auto&& result, GError **gerr) {
if (result)
return MU_OK;
result.error().fill_g_error(err);
result.error().fill_g_error(gerr);
switch(result.error().code()) {
case Error::Code::NoMatches:
return MU_ERROR_NO_MATCHES;
@ -643,9 +643,6 @@ Mu::mu_cmd_execute(const MuConfig* opts, GError** err) try {
case MU_CONFIG_CMD_FIELDS:
merr = mu_error_from_result(mu_cmd_fields(opts), err);
break;
case MU_CONFIG_CMD_FLAGS:
merr = mu_error_from_result(mu_cmd_flags(opts), err);
break;
case MU_CONFIG_CMD_MKDIR: merr = cmd_mkdir(opts, err); break;
case MU_CONFIG_CMD_SCRIPT: merr = mu_cmd_script(opts, err); break;
case MU_CONFIG_CMD_VIEW:

@ -45,7 +45,6 @@ Result<void> mu_cmd_find(const Mu::Store& store, const MuConfig* opts);
*/
Result<void> mu_cmd_extract(const MuConfig* opts);
/**
* execute the 'fields' command
*
@ -55,16 +54,6 @@ Result<void> mu_cmd_extract(const MuConfig* opts);
*/
Result<void> mu_cmd_fields(const MuConfig* opts);
/**
* execute the 'flags' command
*
* @param opts configuration options
*
* @return Ok() or some error
*/
Result<void> mu_cmd_flags(const MuConfig* opts);
/**
* execute the 'script' command
*

@ -444,7 +444,7 @@ cmd_from_string(const char* str)
{"mkdir", MU_CONFIG_CMD_MKDIR}, {"remove", MU_CONFIG_CMD_REMOVE},
{"script", MU_CONFIG_CMD_SCRIPT}, {"server", MU_CONFIG_CMD_SERVER},
{"verify", MU_CONFIG_CMD_VERIFY}, {"view", MU_CONFIG_CMD_VIEW},
{"fields", MU_CONFIG_CMD_FIELDS}, {"flags", MU_CONFIG_CMD_FLAGS}
{"fields", MU_CONFIG_CMD_FIELDS},
};
if (!str)

@ -66,7 +66,6 @@ typedef enum {
MU_CONFIG_CMD_EXTRACT,
MU_CONFIG_CMD_FIELDS,
MU_CONFIG_CMD_FIND,
MU_CONFIG_CMD_FLAGS,
MU_CONFIG_CMD_HELP,
MU_CONFIG_CMD_INDEX,
MU_CONFIG_CMD_INFO,

Loading…
Cancel
Save