diff options
| author | Pranith K <pranithk@gluster.com> | 2010-12-13 06:06:20 +0000 | 
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2010-12-14 19:42:10 -0800 | 
| commit | 1637eabfd3e953a609cd5c82f58a7daa9d88b243 (patch) | |
| tree | cc89fb22c072d845a7927e244952ebf36866da7b | |
| parent | b754e531b48113596fddcd7d0b433ebcbf016c27 (diff) | |
cli: remove duplication of cmd help
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 2089 (Documentation bug in replace-brick options)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2089
| -rw-r--r-- | cli/src/cli-cmd-peer.c | 24 | ||||
| -rw-r--r-- | cli/src/cli-cmd-system.c | 10 | ||||
| -rw-r--r-- | cli/src/cli-cmd-volume.c | 158 | ||||
| -rw-r--r-- | cli/src/cli.c | 12 | ||||
| -rw-r--r-- | cli/src/cli.h | 3 | ||||
| -rw-r--r-- | cli/src/registry.c | 5 | 
6 files changed, 46 insertions, 166 deletions
diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index 1f3ee6240..dc361f539 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -40,24 +40,6 @@ 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 () -{ -        cli_out ("Usage: probe <hostname>"); -} - -void -cli_cmd_deprobe_usage () -{ -        cli_out ("Usage: detach <hostname>"); -} - -void -cli_cmd_peer_status_usage () -{ -        cli_out ("Usage: peer status"); -} -  int  cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word,                     const char **words, int wordcount) @@ -68,7 +50,7 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word,          dict_t                  *dict = NULL;          if (!(wordcount == 3)) { -                cli_cmd_probe_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -113,7 +95,7 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word,          dict_t               *dict  = NULL;          if (!(wordcount == 3) ) { -                cli_cmd_deprobe_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -152,7 +134,7 @@ cli_cmd_peer_status_cbk (struct cli_state *state, struct cli_cmd_word *word,          call_frame_t            *frame = NULL;          if (wordcount != 2) { -                cli_cmd_peer_status_usage (); +                cli_usage_out (word->pattern);                  goto out;          } diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c index 0c1b6d267..e92376cef 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -129,14 +129,8 @@ out:          return ret;  } -void -cli_cmd_fsm_log_usage () -{ -	cli_out ("Usage: fsm log [<peer-name>]"); -} -  int -cli_cmd_fsm_log (struct cli_state *state, struct cli_cmd_word *in_word, +cli_cmd_fsm_log (struct cli_state *state, struct cli_cmd_word *word,                   const char **words, int wordcount)  {          int                             ret = -1; @@ -145,7 +139,7 @@ cli_cmd_fsm_log (struct cli_state *state, struct cli_cmd_word *in_word,          char                            *name = "";          if ((wordcount != 3) && (wordcount != 2)) { -                cli_cmd_fsm_log_usage (); +                cli_usage_out (word->pattern);                  goto out;          } diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index ef62e14f9..3f671a63a 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -41,48 +41,6 @@ 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 () -{ -        cli_out ("Usage: volume start <VOLNAME> [force]"); -} - -void -cli_cmd_volume_stop_usage () -{ -        cli_out ("Usage: volume stop <VOLNAME> [force]"); -} - -void -cli_cmd_volume_rename_usage () -{ -        cli_out ("Usage: volume rename <VOLNAME> <NEW-VOLNAME>"); -} - -void -cli_cmd_volume_delete_usage () -{ -        cli_out ("Usage: volume delete <VOLNAME>"); -} - -void -cli_cmd_volume_info_usage () -{ -        cli_out ("Usage: volume info [all|<VOLNAME>]"); -} - -void -cli_cmd_volume_reset_usage () -{ -        cli_out ("Usage: volume reset <VOLNAME> "); -} - -void -cli_cmd_volume_set_usage () -{ -	cli_out ("Usage: volume set <VOLNAME> <KEY> <VALUE>"); -} -  int  cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word,                           const char **words, int wordcount) @@ -112,7 +70,7 @@ cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word,                  }                  proc = &cli_rpc_prog->proctable[GF1_CLI_GET_VOLUME];          } else { -                cli_cmd_volume_info_usage (); +                cli_usage_out (word->pattern);                  return -1;          } @@ -138,13 +96,6 @@ out:  } - -void -cli_cmd_sync_volume_usage () -{ -        cli_out ("Usage: volume sync <HOSTNAME> [all|<VOLNAME>]"); -} -  int  cli_cmd_sync_volume_cbk (struct cli_state *state, struct cli_cmd_word *word,                           const char **words, int wordcount) @@ -155,7 +106,7 @@ cli_cmd_sync_volume_cbk (struct cli_state *state, struct cli_cmd_word *word,          gf1_cli_sync_volume_req req = {0,};          if ((wordcount < 3) || (wordcount > 4)) { -               cli_cmd_sync_volume_usage (); +               cli_usage_out (word->pattern);                 goto out;          } @@ -184,13 +135,6 @@ out:          return ret;  } -void -cli_cmd_volume_create_usage () -{ -        cli_out ("Usage: volume create <NEW-VOLNAME> " -                 "[stripe <COUNT>] [replica <COUNT>] [transport <tcp|rdma>] " -                 "<NEW-BRICK> ..."); -}  int  cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, @@ -210,7 +154,7 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word,          ret = cli_cmd_volume_create_parse (words, wordcount, &options);          if (ret) { -                cli_cmd_volume_create_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -245,7 +189,7 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word,                  goto out;          if (wordcount != 3) { -                cli_cmd_volume_delete_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -283,7 +227,7 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word,                  goto out;          if (wordcount < 3 || wordcount > 4) { -               cli_cmd_volume_start_usage (); +               cli_usage_out (word->pattern);                 goto out;          } @@ -296,7 +240,7 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word,                          req.flags |= GF_CLI_FLAG_OP_FORCE;                  } else {                          ret = -1; -                        cli_cmd_volume_start_usage (); +                        cli_usage_out (word->pattern);                          goto out;                  }          } @@ -372,7 +316,7 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word,                  goto out;          if (wordcount < 3 || wordcount > 4) { -               cli_cmd_volume_stop_usage (); +               cli_usage_out (word->pattern);                 goto out;          } @@ -385,7 +329,7 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word,                          flags |= GF_CLI_FLAG_OP_FORCE;                  } else {                          ret = -1; -                        cli_cmd_volume_stop_usage (); +                        cli_usage_out (word->pattern);                          goto out;                  }          } @@ -431,7 +375,7 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word,                  goto out;          if (wordcount != 4) { -                cli_cmd_volume_rename_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -462,12 +406,6 @@ out:          return ret;  } -void -cli_cmd_volume_defrag_usage () -{ -        cli_out ("Usage: volume rebalance <VOLNAME> <start|stop|status>"); -} -  int  cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,                             const char **words, int wordcount) @@ -486,7 +424,7 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,                  goto out;          if (wordcount != 4) { -                cli_cmd_volume_defrag_usage(); +                cli_usage_out (word->pattern);                  goto out;          } @@ -536,7 +474,7 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word,          ret = cli_cmd_volume_reset_parse (words, wordcount, &options);          if (ret) { -                cli_cmd_volume_reset_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -572,7 +510,7 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word,          ret = cli_cmd_volume_set_parse (words, wordcount, &options);          if (ret) { -                cli_cmd_volume_set_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -588,13 +526,6 @@ out:  } -void -cli_cmd_volume_add_brick_usage () -{ -        cli_out ("Usage: volume add-brick <VOLNAME> " -                 "<NEW-BRICK> ..."); -} -  int  cli_cmd_volume_add_brick_cbk (struct cli_state *state,                                struct cli_cmd_word *word, const char **words, @@ -612,7 +543,7 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state,          ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options);          if (ret) { -                cli_cmd_volume_add_brick_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -635,13 +566,6 @@ out:  } -void -cli_cmd_volume_remove_brick_usage () -{ -        cli_out ("Usage: volume remove-brick <VOLNAME> " -                 "<BRICK> ..."); -} -  int  cli_cmd_volume_remove_brick_cbk (struct cli_state *state,                                   struct cli_cmd_word *word, const char **words, @@ -663,7 +587,7 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,          ret = cli_cmd_volume_remove_brick_parse (words, wordcount, &options);          if (ret) { -                cli_cmd_volume_remove_brick_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -693,14 +617,6 @@ out:  } -void -cli_cmd_volume_replace_brick_usage () -{ -        cli_out("Usage: volume replace-brick <VOLNAME> " -                "<BRICK> <NEW-BRICK> start|pause|abort|commit|status"); -} - -  int  cli_cmd_volume_replace_brick_cbk (struct cli_state *state,                                    struct cli_cmd_word *word, @@ -721,7 +637,7 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state,          ret = cli_cmd_volume_replace_brick_parse (words, wordcount, &options);          if (ret) { -                cli_cmd_volume_replace_brick_usage (); +                cli_usage_out (word->pattern);                  goto out;          } @@ -750,12 +666,6 @@ cli_cmd_volume_set_transport_cbk (struct cli_state *state,          return 0;  } -void -cli_cmd_log_filename_usage () -{ -        cli_out ("Usage: volume log filename <VOLNAME> [BRICK] <PATH>"); -} -  int  cli_cmd_log_filename_cbk (struct cli_state *state, struct cli_cmd_word *word,                            const char **words, int wordcount) @@ -766,8 +676,8 @@ cli_cmd_log_filename_cbk (struct cli_state *state, struct cli_cmd_word *word,          dict_t                  *options = NULL;          if (!((wordcount == 5) || (wordcount == 6))) { -               cli_cmd_log_filename_usage (); -               goto out; +                cli_usage_out (word->pattern); +                goto out;          }          proc = &cli_rpc_prog->proctable[GF1_CLI_LOG_FILENAME]; @@ -795,12 +705,6 @@ out:  } -void -cli_cmd_log_locate_usage () -{ -        cli_out ("Usage: volume log locate <VOLNAME> [BRICK]"); -} -  int  cli_cmd_log_locate_cbk (struct cli_state *state, struct cli_cmd_word *word,                          const char **words, int wordcount) @@ -811,8 +715,8 @@ cli_cmd_log_locate_cbk (struct cli_state *state, struct cli_cmd_word *word,          dict_t                  *options = NULL;          if (!((wordcount == 4) || (wordcount == 5))) { -               cli_cmd_log_locate_usage (); -               goto out; +                cli_usage_out (word->pattern); +                goto out;          }          proc = &cli_rpc_prog->proctable[GF1_CLI_LOG_LOCATE]; @@ -840,12 +744,6 @@ out:          return ret;  } -void -cli_cmd_log_rotate_usage () -{ -        cli_out ("Usage: volume log rotate <VOLNAME> [BRICK]"); -} -  int  cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word,                          const char **words, int wordcount) @@ -856,8 +754,8 @@ cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word,          dict_t                  *options = NULL;          if (!((wordcount == 4) || (wordcount == 5))) { -               cli_cmd_log_rotate_usage (); -               goto out; +                cli_usage_out (word->pattern); +                goto out;          }          proc = &cli_rpc_prog->proctable[GF1_CLI_LOG_ROTATE]; @@ -918,19 +816,11 @@ struct cli_cmd volume_cmds[] = {            cli_cmd_volume_remove_brick_cbk,            "remove brick from volume <VOLNAME>"}, -        { "volume rebalance <VOLNAME> start", -          cli_cmd_volume_defrag_cbk, -          "start rebalance of volume <VOLNAME>"}, - -        { "volume rebalance <VOLNAME> stop", -          cli_cmd_volume_defrag_cbk, -          "stop rebalance of volume <VOLNAME>"}, - -        { "volume rebalance <VOLNAME> status", +        { "volume rebalance <VOLNAME> {start|stop|status}",            cli_cmd_volume_defrag_cbk, -          "rebalance status of volume <VOLNAME>"}, +          "rebalance operations"}, -        { "volume replace-brick <VOLNAME> (<BRICK> <NEW-BRICK>) start|pause|abort|status", +        { "volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> {start|pause|abort|status}",            cli_cmd_volume_replace_brick_cbk,            "replace-brick operations"}, diff --git a/cli/src/cli.c b/cli/src/cli.c index bb89566e6..a2e4d71bc 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -451,6 +451,18 @@ cli_state_init (struct cli_state *state)          return ret;  } +int +cli_usage_out (const char *usage) +{ +        GF_ASSERT (usage); +        GF_ASSERT (usage[0] != '\0'); + +        if (!usage || usage[0] == '\0') +                return -1; + +        cli_out ("Usage: %s", usage); +        return 0; +}  int  cli_out (const char *fmt, ...) diff --git a/cli/src/cli.h b/cli/src/cli.h index 57be8c6f6..c0fb5a7e5 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -60,7 +60,7 @@ struct cli_cmd_word {          cli_cmd_match_t       *match;          cli_cmd_cbk_t         *cbkfn;          const char            *desc; - +        const char            *pattern;          int                    nextwords_cnt;          struct cli_cmd_word  **nextwords;  }; @@ -158,6 +158,7 @@ int cli_cmd_process_line (struct cli_state *state, const char *line);  int cli_rl_enable (struct cli_state *state);  int cli_rl_out (struct cli_state *state, const char *fmt, va_list ap); +int cli_usage_out (const char *usage);  int cli_out (const char *fmt, ...);  int diff --git a/cli/src/registry.c b/cli/src/registry.c index c3634d974..166a14897 100644 --- a/cli/src/registry.c +++ b/cli/src/registry.c @@ -319,7 +319,7 @@ cli_cmd_newword (struct cli_cmd_word *word, const char *token)  int  cli_cmd_ingest (struct cli_cmd_tree *tree, char **tokens, cli_cmd_cbk_t *cbkfn, -                const char *desc) +                const char *desc, const char *pattern)  {          int                    ret = 0;          char                 **tokenp = NULL; @@ -351,6 +351,7 @@ cli_cmd_ingest (struct cli_cmd_tree *tree, char **tokens, cli_cmd_cbk_t *cbkfn,          word->cbkfn = cbkfn;          word->desc  = desc; +        word->pattern = pattern;          /* end of static strings in command template */ @@ -374,7 +375,7 @@ cli_cmd_register (struct cli_cmd_tree *tree, const char *template,          if (!tokens)                  return -1; -        ret = cli_cmd_ingest (tree, tokens, cbk, desc); +        ret = cli_cmd_ingest (tree, tokens, cbk, desc, template);          if (ret)                  goto err;  | 
