diff --git a/mu/mu-cmd-cfind.cc b/mu/mu-cmd-cfind.cc index 8d4938ae..a6385b63 100644 --- a/mu/mu-cmd-cfind.cc +++ b/mu/mu-cmd-cfind.cc @@ -334,17 +334,17 @@ each_contact(const Mu::Contact& ci, ECData& ecdata) } } -static MuError +static Result run_cmd_cfind(const Mu::Store& store, const char* pattern, gboolean personal, time_t after, int maxnum, const MuConfigFormat format, - gboolean color, - GError** err) + gboolean color) { ECData ecdata{}; + GError *err{}; memset(&ecdata, 0, sizeof(ecdata)); @@ -352,11 +352,10 @@ run_cmd_cfind(const Mu::Store& store, ecdata.rx = g_regex_new( pattern, (GRegexCompileFlags)(G_REGEX_CASELESS | G_REGEX_OPTIMIZE), - (GRegexMatchFlags)0, - err); + (GRegexMatchFlags)0, &err); if (!ecdata.rx) - return MU_ERROR_CONTACTS; + return Err(Error::Code::Internal, &err, "invalid cfind regexp"); } ecdata.personal = personal; @@ -378,17 +377,18 @@ run_cmd_cfind(const Mu::Store& store, if (ecdata.rx) g_regex_unref(ecdata.rx); - if (ecdata.n == 0) { - g_printerr("no matching contacts found\n"); - return MU_ERROR_NO_MATCHES; - } - - return MU_OK; + if (ecdata.n == 0) + return Err(Error::Code::ContactNotFound, "no matching contacts found"); + else + return Ok(); } static gboolean cfind_params_valid(const MuConfig* opts) { + if (!opts || opts->cmd != MU_CONFIG_CMD_CFIND) + return FALSE; + switch (opts->format) { case MU_CONFIG_FORMAT_PLAIN: case MU_CONFIG_FORMAT_MUTT_ALIAS: @@ -413,29 +413,17 @@ cfind_params_valid(const MuConfig* opts) return TRUE; } -MuError -Mu::mu_cmd_cfind(const Mu::Store& store, const MuConfig* opts, GError** err) +Result +Mu::mu_cmd_cfind(const Mu::Store& store, const MuConfig* opts) { - g_return_val_if_fail(opts, MU_ERROR_INTERNAL); - g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_CFIND, MU_ERROR_INTERNAL); - if (!cfind_params_valid(opts)) - throw Mu::Error(Mu::Error::Code::InvalidArgument, - "invalid parameters"); - - auto res = run_cmd_cfind(store, - opts->params[1], - opts->personal, - opts->after, - opts->maxnum, - opts->format, - !opts->nocolor, - err); - - if (res != MU_OK && res != MU_ERROR_NO_MATCHES) - throw Mu::Error(Mu::Error::Code::Internal, - err /*consumes*/, - "error in cfind"); - - return res; + return Err(Error::Code::InvalidArgument, "error in parameters"); + else + return run_cmd_cfind(store, + opts->params[1], + opts->personal, + opts->after, + opts->maxnum, + opts->format, + !opts->nocolor); } diff --git a/mu/mu-cmd-fields.cc b/mu/mu-cmd-fields.cc index e40849fa..a84638d3 100644 --- a/mu/mu-cmd-fields.cc +++ b/mu/mu-cmd-fields.cc @@ -48,7 +48,7 @@ show_fields(const MuConfig* opts) Table fields; fields.add_row({"field-name", "alias", "short", "search", - "value", "example", "description"}); + "value", "example query", "description"}); auto disp= [&](std::string_view sv)->std::string { if (sv.empty()) diff --git a/mu/mu-cmd-index.cc b/mu/mu-cmd-index.cc index c386a04d..1559cd66 100644 --- a/mu/mu-cmd-index.cc +++ b/mu/mu-cmd-index.cc @@ -77,33 +77,20 @@ print_stats(const Indexer::Progress& stats, bool color) << "; cleaned-up: " << col.fg(Color::Green) << stats.removed << col.reset(); } -MuError -Mu::mu_cmd_index(Mu::Store& store, const MuConfig* opts, GError** err) +Result +Mu::mu_cmd_index(Mu::Store& store, const MuConfig* opts) { - g_return_val_if_fail(opts, MU_ERROR); - g_return_val_if_fail(opts->cmd == MU_CONFIG_CMD_INDEX, MU_ERROR); + if (!opts || opts->cmd != MU_CONFIG_CMD_INDEX || opts->params[1]) + return Err(Error::Code::InvalidArgument, "error in parameters"); - /* param[0] == 'index' there should be no param[1] */ - if (opts->params[1]) { - mu_util_g_set_error(err, MU_ERROR_IN_PARAMETERS, "unexpected parameter"); - return MU_ERROR; - } - if (opts->max_msg_size < 0) { - mu_util_g_set_error(err, - MU_ERROR_IN_PARAMETERS, + if (opts->max_msg_size < 0) + return Err(Error::Code::InvalidArgument, "the maximum message size must be >= 0"); - return MU_ERROR; - } const auto mdir{store.properties().root_maildir}; - if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) { - mu_util_g_set_error(err, - MU_ERROR_FILE, - "'%s' is not readable: %s", - mdir.c_str(), - g_strerror(errno)); - return MU_ERROR; - } + if (G_UNLIKELY(access(mdir.c_str(), R_OK) != 0)) + return Err(Error::Code::File, "'%s' is not readable: %s", + mdir.c_str(), g_strerror(errno)); MaybeAnsi col{!opts->nocolor}; using Color = MaybeAnsi::Color; @@ -146,5 +133,5 @@ Mu::mu_cmd_index(Mu::Store& store, const MuConfig* opts, GError** err) std::cout << std::endl; } - return MU_OK; + return Ok(); } diff --git a/mu/mu-cmd-script.cc b/mu/mu-cmd-script.cc index 3f119a3f..187b6b4d 100644 --- a/mu/mu-cmd-script.cc +++ b/mu/mu-cmd-script.cc @@ -43,20 +43,20 @@ using namespace Mu; static void print_script(const char* name, - const char* oneline, - const char* descr, - gboolean color, - gboolean verbose) + const char* oneline, + const char* descr, + gboolean color, + gboolean verbose) { g_print("%s%s%s%s%s%s%s%s", - verbose ? "\n" : " * ", - COL(MU_COLOR_GREEN), - name, - COL(MU_COLOR_DEFAULT), - oneline ? ": " : "", - COL(MU_COLOR_BLUE), - oneline ? oneline : "", - MU_COLOR_DEFAULT); + verbose ? "\n" : " * ", + COL(MU_COLOR_GREEN), + name, + COL(MU_COLOR_DEFAULT), + oneline ? ": " : "", + COL(MU_COLOR_BLUE), + oneline ? oneline : "", + MU_COLOR_DEFAULT); if (verbose && descr) g_print("%s%s%s", COL(MU_COLOR_MAGENTA), descr, COL(MU_COLOR_DEFAULT)); @@ -109,10 +109,10 @@ get_userpath(const char* muhome) return g_build_path(G_DIR_SEPARATOR_S, muhome, "scripts", NULL); else return g_build_path(G_DIR_SEPARATOR_S, - g_get_user_data_dir(), - "mu", - "scripts", - NULL); + g_get_user_data_dir(), + "mu", + "scripts", + NULL); } static GSList* @@ -122,9 +122,9 @@ get_script_info_list(const char* muhome, GError** err) char* userpath; scripts = mu_script_get_script_info_list(MU_SCRIPTS_DIR, - MU_GUILE_EXT, - MU_GUILE_DESCR_PREFIX, - err); + MU_GUILE_EXT, + MU_GUILE_DESCR_PREFIX, + err); if (err && *err) return NULL; @@ -158,51 +158,44 @@ get_script_info_list(const char* muhome, GError** err) return userscripts; /* apparently, scripts was NULL */ } -static gboolean -check_params(const MuConfig* opts, GError** err) +Mu::Result +Mu::mu_cmd_script(const MuConfig* opts) { - if (!mu_util_supports(MU_FEATURE_GUILE)) { - mu_util_g_set_error(err, - MU_ERROR_IN_PARAMETERS, - "the 'script' command is not available " - "in this version of mu"); - return FALSE; - } + GError *err{}; + MuScriptInfo* msi; + GSList* scripts; - return TRUE; -} + if (!mu_util_supports(MU_FEATURE_GUILE)) + return Err(Error::Code::InvalidArgument, + "