* add some extra error checking for the right command
This commit is contained in:
@ -81,6 +81,7 @@ mu_cmd_extract (MuConfigOptions *opts)
|
|||||||
gboolean rv;
|
gboolean rv;
|
||||||
|
|
||||||
g_return_val_if_fail (opts, FALSE);
|
g_return_val_if_fail (opts, FALSE);
|
||||||
|
g_return_val_if_fail (mu_cmd_equals (opts, "extract"), FALSE);
|
||||||
|
|
||||||
/* note: params[0] will be 'view' */
|
/* note: params[0] will be 'view' */
|
||||||
if (!opts->params[0] || !opts->params[1]) {
|
if (!opts->params[0] || !opts->params[1]) {
|
||||||
|
|||||||
@ -325,6 +325,7 @@ mu_cmd_find (MuConfigOptions *opts)
|
|||||||
const gchar **params;
|
const gchar **params;
|
||||||
|
|
||||||
g_return_val_if_fail (opts, FALSE);
|
g_return_val_if_fail (opts, FALSE);
|
||||||
|
g_return_val_if_fail (mu_cmd_equals (opts, "find"), FALSE);
|
||||||
|
|
||||||
if (!query_params_valid (opts))
|
if (!query_params_valid (opts))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|||||||
@ -173,6 +173,8 @@ mu_cmd_cleanup (MuConfigOptions *opts)
|
|||||||
MuIndexStats stats;
|
MuIndexStats stats;
|
||||||
|
|
||||||
g_return_val_if_fail (opts, FALSE);
|
g_return_val_if_fail (opts, FALSE);
|
||||||
|
g_return_val_if_fail (mu_cmd_equals (opts, "cleanup"), FALSE);
|
||||||
|
|
||||||
|
|
||||||
if (!check_index_params (opts))
|
if (!check_index_params (opts))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -225,6 +227,7 @@ mu_cmd_index (MuConfigOptions *opts)
|
|||||||
MuIndexStats stats;
|
MuIndexStats stats;
|
||||||
|
|
||||||
g_return_val_if_fail (opts, FALSE);
|
g_return_val_if_fail (opts, FALSE);
|
||||||
|
g_return_val_if_fail (mu_cmd_equals (opts, "find"), FALSE);
|
||||||
|
|
||||||
if (!check_index_params (opts))
|
if (!check_index_params (opts))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|||||||
@ -35,8 +35,8 @@ mu_cmd_mkdir (MuConfigOptions *opts)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!opts->params[0])
|
g_return_val_if_fail (opts, FALSE);
|
||||||
return FALSE; /* shouldn't happen */
|
g_return_val_if_fail (mu_cmd_equals (opts, "mkdir"), FALSE);
|
||||||
|
|
||||||
if (!opts->params[1]) {
|
if (!opts->params[1]) {
|
||||||
g_printerr (
|
g_printerr (
|
||||||
|
|||||||
15
src/mu-cmd.c
15
src/mu-cmd.c
@ -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
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
@ -28,6 +28,19 @@
|
|||||||
#include "mu-maildir.h"
|
#include "mu-maildir.h"
|
||||||
#include "mu-cmd.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
|
static MuCmd
|
||||||
cmd_from_string (const char* cmd)
|
cmd_from_string (const char* cmd)
|
||||||
{
|
{
|
||||||
|
|||||||
14
src/mu-cmd.h
14
src/mu-cmd.h
@ -38,6 +38,17 @@ enum _MuCmd {
|
|||||||
};
|
};
|
||||||
typedef enum _MuCmd 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
|
* try to execute whatever is specified on the command line
|
||||||
*
|
*
|
||||||
@ -47,8 +58,6 @@ typedef enum _MuCmd MuCmd;
|
|||||||
*/
|
*/
|
||||||
gboolean mu_cmd_execute (MuConfigOptions *config);
|
gboolean mu_cmd_execute (MuConfigOptions *config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute the 'mkdir' command
|
* execute the 'mkdir' command
|
||||||
*
|
*
|
||||||
@ -108,7 +117,6 @@ gboolean mu_cmd_find (MuConfigOptions *opts);
|
|||||||
*/
|
*/
|
||||||
gboolean mu_cmd_extract (MuConfigOptions *opts);
|
gboolean mu_cmd_extract (MuConfigOptions *opts);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /*__MU_CMD_H__*/
|
#endif /*__MU_CMD_H__*/
|
||||||
|
|||||||
Reference in New Issue
Block a user