diff options
author | Csaba Henk <csaba@gluster.com> | 2010-09-15 08:11:15 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-09-16 23:07:27 -0700 |
commit | 63ec13f022ae99c1664fbdbc9e6623903ba843af (patch) | |
tree | fdde04563f5081e4322c0bf75541631293100fd8 /cli/src/cli.c | |
parent | 47bc630dca589235d7c10e2748cebaa5e419d5d7 (diff) |
cli: add a simplistic option parser, convert "mode script" to "--mode=script"
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 1570 (geosync related changes)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570
Diffstat (limited to 'cli/src/cli.c')
-rw-r--r-- | cli/src/cli.c | 38 |
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; } |