diff options
Diffstat (limited to 'cli/src')
-rw-r--r-- | cli/src/cli-cmd-misc.c | 10 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 2 | ||||
-rw-r--r-- | cli/src/cli.c | 38 | ||||
-rw-r--r-- | cli/src/cli.h | 5 | ||||
-rw-r--r-- | cli/src/input.c | 21 |
5 files changed, 44 insertions, 32 deletions
diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c index 7833456b7..306a7628f 100644 --- a/cli/src/cli-cmd-misc.c +++ b/cli/src/cli-cmd-misc.c @@ -61,10 +61,8 @@ cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word, for (cmd = cli_probe_cmds; cmd->pattern; cmd++) cli_out ("%s - %s", cmd->pattern, cmd->desc); - for (cmd = cli_misc_cmds; cmd->pattern; cmd++) { - if (cmd->cbk) - cli_out ("%s - %s", cmd->pattern, cmd->desc); - } + for (cmd = cli_misc_cmds; cmd->pattern; cmd++) + cli_out ("%s - %s", cmd->pattern, cmd->desc); if (!state->rl_enabled) exit (0); @@ -81,10 +79,6 @@ struct cli_cmd cli_misc_cmds[] = { cli_cmd_display_help, "display command options"}, - { "mode script", - NULL, - "assign gluster execution mode"}, - { NULL, NULL, NULL } }; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 539c7eeac..b8a5df6d6 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -242,7 +242,7 @@ cli_cmd_get_confirmation (struct cli_state *state, const char *question) char answer = '\0'; char flush = '\0'; - if (GLUSTER_MODE_SCRIPT == state->mode) + if (state->mode & GLUSTER_MODE_SCRIPT) return GF_ANSWER_YES; printf ("%s (y/n) ", question); answer = getchar (); diff --git a/cli/src/cli.c b/cli/src/cli.c index 58cb61bb4..4e25417f9 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -325,13 +325,49 @@ cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, } int +cli_opt_parse (char *opt, struct cli_state *state) +{ + char *oarg; + + oarg = strtail (opt, "mode="); + if (oarg) { + if (strcmp (oarg, "script") == 0) { + state->mode |= GLUSTER_MODE_SCRIPT; + return 0; + } + if (strcmp (oarg, "interactive") == 0) + return 0; + return -1; + } + + return -1; +} + +int parse_cmdline (int argc, char *argv[], struct cli_state *state) { int ret = 0; + int i = 0; + int j = 0; + char *opt = NULL; - state->argc=argc-1; + state->argc=argc-1; state->argv=&argv[1]; + for (i = 0; i < state->argc; i++) { + opt = strtail (state->argv[i], "--"); + if (opt) { + ret = cli_opt_parse (opt, state); + if (ret == -1) { + cli_out ("unrecognized option --%s", opt); + return ret; + } + for (j = i; j < state->argc - 1; j++) + state->argv[j] = state->argv[j + 1]; + state->argc--; + } + } + return ret; } diff --git a/cli/src/cli.h b/cli/src/cli.h index eaa638c29..62aa02079 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -39,9 +39,8 @@ enum argp_option_keys { ARGP_PORT_KEY = 'p', }; -enum gluster_mode { - GLUSTER_MODE_SCRIPT = 1 -}; +#define GLUSTER_MODE_SCRIPT (1 << 0) + struct cli_state; struct cli_cmd_word; struct cli_cmd_tree; diff --git a/cli/src/input.c b/cli/src/input.c index 2c67b354d..7c3e78b16 100644 --- a/cli/src/input.c +++ b/cli/src/input.c @@ -41,10 +41,7 @@ cli_batch (void *d) state = d; - if (state->mode == GLUSTER_MODE_SCRIPT) - ret = cli_cmd_process (state, state->argc - 2, state->argv + 2); - else - ret = cli_cmd_process (state, state->argc, state->argv); + ret = cli_cmd_process (state, state->argc, state->argv); gf_log ("", GF_LOG_NORMAL, "Exiting with: %d", ret); exit (ret); @@ -86,22 +83,8 @@ int cli_input_init (struct cli_state *state) { int ret = 0; - gf_boolean_t is_batch = _gf_false; - - if (1 < state->argc) { - if (!strcmp ("mode", state->argv[0]) && - !strcmp ("script", state->argv[1])) { - state->mode = GLUSTER_MODE_SCRIPT; - if (2 < state->argc) - is_batch = _gf_true; - } else { - is_batch = _gf_true; - } - } else if (1 == state->argc) { - is_batch = _gf_true; - } - if (is_batch) { + if (state->argc) { ret = pthread_create (&state->input, NULL, cli_batch, state); return ret; } |