* mu-config: better argument check, print usage info when no command is provided

This commit is contained in:
Dirk-Jan C. Binnema 2011-01-13 21:41:07 +02:00
parent 4aa838f6f6
commit a9a2e1f94f
1 changed files with 5 additions and 4 deletions

View File

@ -249,15 +249,16 @@ parse_cmd (MuConfig *opts, int *argcp, char ***argvp)
opts->cmdstr = NULL; opts->cmdstr = NULL;
if (*argcp < 2) /* no command found at all */ if (*argcp < 2) /* no command found at all */
return FALSE; return TRUE;
else if ((**argvp)[1] == '-') else if ((**argvp)[1] == '-')
/* if the first param starts with '-', there is no /* if the first param starts with '-', there is no
* command, just some option (like --version, --help * command, just some option (like --version, --help
* etc.)*/ * etc.)*/
return TRUE; return TRUE;
opts->cmd = MU_CONFIG_CMD_UNKNOWN; opts->cmd = MU_CONFIG_CMD_UNKNOWN;
opts->cmdstr = (*argvp)[1]; opts->cmdstr = (*argvp)[1];
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i) for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
if (strcmp (opts->cmdstr, cmd_map[i]._name) == 0) if (strcmp (opts->cmdstr, cmd_map[i]._name) == 0)
opts->cmd = cmd_map[i]._cmd; opts->cmd = cmd_map[i]._cmd;
@ -376,14 +377,14 @@ mu_config_execute (MuConfig *opts)
show_version (); show_version ();
return MU_EXITCODE_OK; return MU_EXITCODE_OK;
} }
if (!opts->params||!opts->params[0]) {/* no command? */ if (!opts->params||!opts->params[0]) {/* no command? */
show_version (); show_version ();
g_print ("\n"); g_print ("\n");
show_usage (TRUE); show_usage (TRUE);
return MU_EXITCODE_ERROR; return MU_EXITCODE_ERROR;
} }
switch (opts->cmd) { switch (opts->cmd) {
case MU_CONFIG_CMD_CLEANUP: return mu_cmd_cleanup (opts); case MU_CONFIG_CMD_CLEANUP: return mu_cmd_cleanup (opts);
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts); case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts);