* centralize formatstr parsing, cleanup

This commit is contained in:
Dirk-Jan C. Binnema
2011-07-27 08:20:06 +03:00
parent 63076fe222
commit 0a6161a71c
5 changed files with 222 additions and 174 deletions

View File

@ -164,7 +164,7 @@ handle_msg (const char *fname, MuConfig *opts)
g_error_free (err);
return MU_EXITCODE_ERROR;
}
if (view_msg (msg, NULL, opts->summary, opts->color))
rv = MU_EXITCODE_OK;
else
@ -175,6 +175,29 @@ handle_msg (const char *fname, MuConfig *opts)
return rv;
}
static gboolean
view_params_valid (MuConfig *opts)
{
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
g_warning ("usage: mu view [options] <file> [<files>]");
return FALSE;
}
switch (opts->format) {
case MU_CONFIG_FORMAT_PLAIN:
case MU_CONFIG_FORMAT_SEXP:
break;
default:
g_warning ("invalid output format %s",
opts->formatstr ? opts->formatstr : "<none>");
return FALSE;
}
return TRUE;
}
MuExitCode
mu_cmd_view (MuConfig *opts)
@ -184,12 +207,9 @@ mu_cmd_view (MuConfig *opts)
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VIEW,
MU_EXITCODE_ERROR);
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
g_warning ("usage: mu view [options] <file> [<files>]");
if (!view_params_valid(opts))
return MU_EXITCODE_ERROR;
}
for (i = 1; opts->params[i]; ++i) {