summaryrefslogtreecommitdiffstats
path: root/cli/src/cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/cli.c')
-rw-r--r--cli/src/cli.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 58cb61bb417..4e25417f9ba 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;
}