mu: make command output more useful

This commit is contained in:
Dirk-Jan C. Binnema 2020-02-08 14:27:52 +02:00
parent e1e26d1da2
commit 4e5f6b4b0a
2 changed files with 39 additions and 15 deletions

View File

@ -29,8 +29,12 @@
#include "mu-config.h"
#include "mu-cmd.h"
static MuConfig MU_CONFIG;
#define color_maybe(C) (MU_CONFIG.nocolor ? "" : (C))
static MuConfigFormat
get_output_format (const char *formatstr)
{
@ -151,11 +155,35 @@ config_options_group_init (void)
return og;
}
static gboolean
index_post_parse_func (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error)
{
if (!MU_CONFIG.maildir && !MU_CONFIG.my_addresses)
return TRUE;
g_printerr ("%sNOTE%s: as of mu 1.3.8, 'mu index' no longer uses the\n"
"--maildir/-m or --my-address options.\n\n",
color_maybe(MU_COLOR_RED), color_maybe(MU_COLOR_DEFAULT));
g_printerr ("Instead, these options should be passed to 'mu init'.\n");
g_printerr ("See the mu-init(1) or the mu4e reference manual,\n'Initializing the message store' for details.\n\n");
return TRUE;
}
static GOptionGroup*
config_options_group_index (void)
{
GOptionGroup *og;
GOptionEntry entries[] = {
/* only here so we can tell users they are deprecated */
{"maildir", 'm', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
&MU_CONFIG.maildir, "top of the maildir", "<maildir>"},
{"my-address", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY,
&MU_CONFIG.my_addresses, "my e-mail address; can be used multiple times",
"<address>"},
{"lazy-check", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.lazycheck,
"only check dir-timestamps (false)", NULL},
{"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY,
@ -167,10 +195,10 @@ config_options_group_index (void)
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
og = g_option_group_new("index",
"Options for the 'index' command",
og = g_option_group_new("index", "Options for the 'index' command",
"", NULL, NULL);
g_option_group_add_entries(og, entries);
g_option_group_set_parse_hooks(og, NULL, (GOptionParseFunc)index_post_parse_func);
return og;
}
@ -434,10 +462,6 @@ config_options_group_server (void)
{
GOptionGroup *og;
GOptionEntry entries[] = {
{"my-address", 0, 0, G_OPTION_ARG_STRING_ARRAY,
&MU_CONFIG.my_addresses,
"my e-mail address; can be used multiple times",
"<address>"},
{"commands", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.commands,
"list the available command and their parameters, then exit", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}

View File

@ -52,6 +52,11 @@ handle_error (MuConfig *conf, MuError merr, GError **err)
if (!(err && *err))
return;
if (*err)
g_printerr ("error: %s (%u)\n",
(*err)->message,
(*err)->code);
switch ((*err)->code) {
case MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK:
g_printerr ("maybe mu is already running?\n");
@ -70,21 +75,16 @@ handle_error (MuConfig *conf, MuError merr, GError **err)
"'mu script' for the scripts\n");
break;
case MU_ERROR_XAPIAN_CANNOT_OPEN:
g_printerr("Please (re)init mu with 'mu init' "
"see mu-init(1) for details");
g_printerr("Please (re)initialize mu with 'mu init' "
"see mu-init(1) for details\n");
return;
case MU_ERROR_XAPIAN_SCHEMA_MISMATCH:
g_printerr("Please (re)init mu with 'mu init' "
"see mu-init(1) for details");
g_printerr("Please (re)initialize mu with 'mu init' "
"see mu-init(1) for details\n");
return;
default:
break; /* nothing to do */
}
if (*err)
g_printerr ("mu: %s (%u)\n",
(*err)->message,
(*err)->code);
}