From cb0352cd4f4748ee6e33bc64d2e2b09d09fe20eb Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Tue, 7 Sep 2010 04:03:31 +0000 Subject: cli: add script mode for gluster Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1554 (add script mode for gluster) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1554 --- cli/src/cli-cmd-volume.c | 50 +++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'cli/src/cli-cmd-volume.c') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index ce831055740..01fff9bf11a 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -236,6 +236,24 @@ out: return ret; } +gf_answer_t +cli_cmd_get_confirmation (struct cli_state *state, const char *question) +{ + char answer = '\0'; + char flush = '\0'; + + if (GLUSTER_MODE_SCRIPT == state->mode) + return GF_ANSWER_YES; + printf ("%s (y/n) ", question); + answer = getchar (); + flush = answer; + while ('\n' != flush) + flush = getchar (); + if ('y' != answer) { + return GF_ANSWER_NO; + } + return GF_ANSWER_YES; +} int cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, @@ -246,8 +264,10 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, call_frame_t *frame = NULL; int flags = 0; gf1_cli_stop_vol_req req = {0,}; - char answer; - char flush; + gf_answer_t answer = GF_ANSWER_NO; + + const char *question = "Stopping volume will make its data inaccessible. " + "Do you want to Continue?"; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -272,13 +292,9 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, } } - printf ("Stopping volume will make its data inaccessible. " - "Do you want to Continue? (y/n) "); - answer = getchar (); - flush = answer; - while ('\n' != flush) - flush = getchar (); - if ('y' != answer) { + answer = cli_cmd_get_confirmation (state, question); + + if (GF_ANSWER_NO == answer) { ret = 0; goto out; } @@ -473,8 +489,10 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *options = NULL; - char answer; - char flush; + gf_answer_t answer = GF_ANSWER_NO; + + const char *question = "Removing brick(s) can result in data loss. " + "Do you want to Continue?"; frame = create_frame (THIS, THIS->ctx->pool); if (!frame) @@ -487,13 +505,9 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, goto out; } - printf ("Removing brick(s) can result in data loss. " - "Do you want to Continue? (y/n) "); - answer = getchar (); - flush = answer; - while ('\n' != flush) - flush = getchar (); - if ('y' != answer) { + answer = cli_cmd_get_confirmation (state, question); + + if (GF_ANSWER_NO == answer) { ret = 0; goto out; } -- cgit