From a0c874f09e294ec75a18a5436bd01eaa97f22f81 Mon Sep 17 00:00:00 2001 From: Kaushik BV Date: Wed, 25 Aug 2010 01:58:23 +0000 Subject: Help Added to the Gluster-CLI for all sub commands (some deletions in the old patch) Signed-off-by: Kaushik BV Signed-off-by: Anand V. Avati BUG: 1156 (gluster --help should display all the options) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1156 --- cli/src/cli-cmd-log.c | 25 +++++++++++++++++++++ cli/src/cli-cmd-peer.c | 26 ++++++++++++++++++++++ cli/src/cli-cmd-volume.c | 24 ++++++++++++++++++++ cli/src/cli-cmd.c | 8 ++++++- cli/src/cli.c | 58 +++--------------------------------------------- 5 files changed, 85 insertions(+), 56 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-log.c b/cli/src/cli-cmd-log.c index 1b71f2f928f..e67f28091e8 100644 --- a/cli/src/cli-cmd-log.c +++ b/cli/src/cli-cmd-log.c @@ -37,6 +37,9 @@ extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; +int cli_cmd_log_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); + int cli_cmd_log_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) @@ -49,10 +52,32 @@ struct cli_cmd cli_log_cmds[] = { { "log ...", cli_cmd_log_cbk, "set log level for "}, + + { "log --help", + cli_cmd_log_help_cbk, + "help command for log"}, { NULL, NULL, NULL } }; +int +cli_cmd_log_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount) +{ + struct cli_cmd *cmd = NULL; + + + + for (cmd = cli_log_cmds; cmd->pattern; cmd++) + cli_out ("%s - %s", cmd->pattern, cmd->desc); + + + + if (!state->rl_enabled) + exit (0); + + return 0; +} int cli_cmd_log_register (struct cli_state *state) diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index f1847a68cbc..fef29c164ec 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -37,6 +37,9 @@ extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; +int cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); + void cli_cmd_probe_usage () { @@ -184,10 +187,33 @@ struct cli_cmd cli_probe_cmds[] = { { "peer status", cli_cmd_peer_status_cbk, "list status of peers"}, + + { "peer --help", + cli_cmd_peer_help_cbk, + "Help command for peer "}, + { NULL, NULL, NULL } }; +int +cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount) +{ + struct cli_cmd *cmd = NULL; + + + + for (cmd = cli_probe_cmds; cmd->pattern; cmd++) + cli_out ("%s - %s", cmd->pattern, cmd->desc); + + + + if (!state->rl_enabled) + exit (0); + + return 0; +} int cli_cmd_probe_register (struct cli_state *state) diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index ae2b6b2aaae..283233cf94e 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -36,6 +36,10 @@ extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; +int +cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); + void cli_cmd_volume_start_usage () { @@ -503,9 +507,29 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_set_cbk, "set options for volume "}, + { "volume --help", + cli_cmd_volume_help_cbk, + "display help for the volume command"}, + + { NULL, NULL, NULL } }; +int +cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount) +{ + struct cli_cmd *cmd = NULL; + + for (cmd = volume_cmds; cmd->pattern; cmd++) + cli_out ("%s - %s", cmd->pattern, cmd->desc); + + + if (!state->rl_enabled) + exit (0); + + return 0; +} int cli_cmd_volume_register (struct cli_state *state) diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index e526fe8895d..ae4e2db2c1f 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -44,6 +44,9 @@ static pthread_mutex_t conn_mutex = PTHREAD_MUTEX_INITIALIZER; int cli_op_ret = 0; int connected = 0; +int cli_cmd_log_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); + static gf_boolean_t cli_cmd_needs_connection (struct cli_cmd_word *word) { @@ -92,6 +95,9 @@ cli_cmd_process (struct cli_state *state, int argc, char **argv) return -1; } + if ( strcmp (word->word,"--help")==0 ) + goto callback; + await_conn = cli_cmd_needs_connection (word); if (await_conn) { @@ -104,7 +110,7 @@ cli_cmd_process (struct cli_state *state, int argc, char **argv) } } - +callback: ret = word->cbkfn (state, word, (const char **)argv, argc); return ret; diff --git a/cli/src/cli.c b/cli/src/cli.c index c165255a0ef..48490ddf4c5 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -76,9 +76,6 @@ extern int connected; /* using argp for command line parsing */ -static char gf_doc[] = ""; - -static char argp_doc[] = "COMMAND [PARAM ...]"; const char *argp_program_version = "" \ PACKAGE_NAME" "PACKAGE_VERSION" built on "__DATE__" "__TIME__ \ @@ -91,14 +88,7 @@ const char *argp_program_version = "" \ const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; -static struct argp_option gf_options[] = { - {0, 0, 0, 0, "Basic options:"}, - {"debug", ARGP_DEBUG_KEY, 0, 0, - "Process runs in foreground and logs to console"}, - {"remote-port", ARGP_PORT_KEY, "PORT", 0, - "glusterd port to connect with"}, - {0, } -}; + struct rpc_clnt *global_rpc; @@ -107,44 +97,7 @@ rpc_clnt_prog_t *cli_rpc_prog; extern struct rpc_clnt_program cli3_1_prog; -static error_t -parse_opts (int key, char *arg, struct argp_state *argp_state) -{ - struct cli_state *state = NULL; - char **argv = NULL; - - state = argp_state->input; - - switch (key) { - case ARGP_DEBUG_KEY: - break; - case ARGP_PORT_KEY: - state->remote_port = strtol (arg, NULL, 0); - break; - case ARGP_KEY_ARG: - if (!state->argc) { - argv = calloc (state->argc + 2, - sizeof (*state->argv)); - } else { - argv = realloc (state->argv, (state->argc + 2) * - sizeof (*state->argv)); - } - if (!argv) - return -1; - - state->argv = argv; - - argv[state->argc] = strdup (arg); - if (!argv[state->argc]) - return -1; - state->argc++; - argv[state->argc] = NULL; - - break; - } - return 0; -} static char * @@ -375,14 +328,9 @@ int parse_cmdline (int argc, char *argv[], struct cli_state *state) { int ret = 0; - struct argp argp = { 0,}; - - argp.options = gf_options; - argp.parser = parse_opts; - argp.args_doc = argp_doc; - argp.doc = gf_doc; - ret = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, NULL, state); + state->argc=argc-1; + state->argv=&argv[1]; return ret; } -- cgit