* add some extra error checking for the right command

This commit is contained in:
Dirk-Jan C. Binnema 2010-08-29 16:39:27 +03:00
parent d5329d3696
commit a7a08dde7f
6 changed files with 34 additions and 8 deletions

View File

@ -81,7 +81,8 @@ mu_cmd_extract (MuConfigOptions *opts)
gboolean rv;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "extract"), FALSE);
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
g_warning ("missing mail file to extract something from");

View File

@ -325,6 +325,7 @@ mu_cmd_find (MuConfigOptions *opts)
const gchar **params;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "find"), FALSE);
if (!query_params_valid (opts))
return FALSE;

View File

@ -173,6 +173,8 @@ mu_cmd_cleanup (MuConfigOptions *opts)
MuIndexStats stats;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "cleanup"), FALSE);
if (!check_index_params (opts))
return FALSE;
@ -225,6 +227,7 @@ mu_cmd_index (MuConfigOptions *opts)
MuIndexStats stats;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "find"), FALSE);
if (!check_index_params (opts))
return FALSE;

View File

@ -34,10 +34,10 @@ gboolean
mu_cmd_mkdir (MuConfigOptions *opts)
{
int i;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "mkdir"), FALSE);
if (!opts->params[0])
return FALSE; /* shouldn't happen */
if (!opts->params[1]) {
g_printerr (
"usage: mu mkdir [-u,--mode=<mode>] "

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2010 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
@ -28,6 +28,19 @@
#include "mu-maildir.h"
#include "mu-cmd.h"
gboolean
mu_cmd_equals (MuConfigOptions *config, const gchar *cmd)
{
g_return_val_if_fail (config, FALSE);
g_return_val_if_fail (cmd, FALSE);
if (!config->params || !config->params[0])
return FALSE;
return (strcmp (config->params[0], cmd) == 0);
}
static MuCmd
cmd_from_string (const char* cmd)
{

View File

@ -38,6 +38,17 @@ enum _MuCmd {
};
typedef enum _MuCmd MuCmd;
/**
* check whether the MuConfigOptions are for command X
*
* @param config the config options
* @param cmd the command to check (ie., "mkdir" or "find")
*
* @return TRUE if the options are for cmd, FALSE otherwise
*/
gboolean mu_cmd_equals (MuConfigOptions *config, const gchar *cmd);
/**
* try to execute whatever is specified on the command line
*
@ -47,8 +58,6 @@ typedef enum _MuCmd MuCmd;
*/
gboolean mu_cmd_execute (MuConfigOptions *config);
/**
* execute the 'mkdir' command
*
@ -108,7 +117,6 @@ gboolean mu_cmd_find (MuConfigOptions *opts);
*/
gboolean mu_cmd_extract (MuConfigOptions *opts);
G_END_DECLS
#endif /*__MU_CMD_H__*/