From c83b6f73f08eb81788dd1fe35c461b19dc9405df Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 25 Aug 2010 02:09:06 +0000 Subject: cli: print usage message when parsing of cmd fails Signed-off-by: Pranith Kumar K Signed-off-by: Anand V. Avati BUG: 1432 (print usage string in case of command parse errors) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1432 --- cli/src/cli-cmd-volume.c | 53 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 283233cf94e..92307ceb3ad 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -332,6 +332,12 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, return 0; } +void +cli_cmd_volume_add_brick_usage () +{ + cli_out ("usage: volume add-brick " + "[(replica )|(stripe )] ..."); +} int cli_cmd_volume_add_brick_cbk (struct cli_state *state, @@ -349,8 +355,11 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options); - if (ret) + if (ret) { + printf("Command Parsing failed, "); + cli_cmd_volume_add_brick_usage (); goto out; + } proc = &cli_rpc_prog->proctable[GF1_CLI_ADD_BRICK]; @@ -360,13 +369,22 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, out: if (!proc && ret) { - char *volname = (char *) words[2]; - cli_out ("Adding brick to Volume %s failed",volname ); + if (wordcount > 2) { + char *volname = (char *) words[2]; + cli_out ("Adding brick to Volume %s failed",volname ); + } } return ret; } +void +cli_cmd_volume_remove_brick_usage () +{ + cli_out ("usage: volume remove-brick " + "[(replica )|(stripe )] ..."); +} + int cli_cmd_volume_remove_brick_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, @@ -383,8 +401,11 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, ret = cli_cmd_volume_remove_brick_parse (words, wordcount, &options); - if (ret) + if (ret) { + printf("Command Parsing failed, "); + cli_cmd_volume_remove_brick_usage (); goto out; + } proc = &cli_rpc_prog->proctable[GF1_CLI_REMOVE_BRICK]; @@ -394,14 +415,21 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, out: if (!proc && ret) { - char *volname = (char *) words[2]; - cli_out ("Removing brick from Volume %s failed",volname ); + if (wordcount > 2) { + char *volname = (char *) words[2]; + cli_out ("Removing brick from Volume %s failed",volname ); + } } return ret; } - +void +cli_cmd_volume_replace_brick_usage () +{ + cli_out("usage: volume replace-brick " + "( )|pause|abort|start|status"); +} int @@ -423,8 +451,11 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, ret = cli_cmd_volume_replace_brick_parse (words, wordcount, &options); - if (ret) + if (ret) { + printf("Command Parsing failed, "); + cli_cmd_volume_replace_brick_usage (); goto out; + } if (proc->fn) { ret = proc->fn (frame, THIS, options); @@ -432,8 +463,10 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, out: if (ret) { - char *volname = (char *) words[2]; - cli_out ("Replacing brick from Volume %s failed",volname ); + if (wordcount > 2) { + char *volname = (char *) words[2]; + cli_out ("Replacing brick from Volume %s failed",volname ); + } } return ret; -- cgit