summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-08-17 03:37:46 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-08-17 02:23:59 -0700
commite5737546071bd1d38430503bb64b9998bd7870dd (patch)
treec5a9fe82f2474ff6c8792381c1b77384c9f82983 /cli/src
parentead92558ee8ec71442b2fa2da1a0df197ee78467 (diff)
cli: Implement help command
Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1229 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1229
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-log.c10
-rw-r--r--cli/src/cli-cmd-misc.c40
-rw-r--r--cli/src/cli-cmd-peer.c14
-rw-r--r--cli/src/cli-cmd-volume.c47
-rw-r--r--cli/src/cli-cmd.c3
-rw-r--r--cli/src/cli-cmd.h1
-rw-r--r--cli/src/cli.h3
-rw-r--r--cli/src/registry.c8
8 files changed, 94 insertions, 32 deletions
diff --git a/cli/src/cli-cmd-log.c b/cli/src/cli-cmd-log.c
index 9b905965dc6..0365f57cb53 100644
--- a/cli/src/cli-cmd-log.c
+++ b/cli/src/cli-cmd-log.c
@@ -46,10 +46,11 @@ cli_cmd_log_cbk (struct cli_state *state, struct cli_cmd_word *word,
}
struct cli_cmd cli_log_cmds[] = {
- { "log [VOLNAME] ...",
- cli_cmd_log_cbk },
+ { "log <VOLNAME> ...",
+ cli_cmd_log_cbk,
+ "set log level for <VOLNAME>"},
- { NULL, NULL }
+ { NULL, NULL, NULL }
};
@@ -60,7 +61,8 @@ cli_cmd_log_register (struct cli_state *state)
struct cli_cmd *cmd = NULL;
for (cmd = cli_log_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk);
+ ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk,
+ cmd->desc);
if (ret)
goto out;
}
diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c
index 9e78ca607e1..1c99bf93052 100644
--- a/cli/src/cli-cmd-misc.c
+++ b/cli/src/cli-cmd-misc.c
@@ -37,6 +37,11 @@ extern struct rpc_clnt *global_rpc;
extern rpc_clnt_prog_t *cli_rpc_prog;
+extern struct cli_cmd volume_cmds[];
+extern struct cli_cmd cli_probe_cmds[];
+extern struct cli_cmd cli_log_cmds[];
+struct cli_cmd cli_misc_cmds[];
+
int
cli_cmd_quit_cbk (struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount)
@@ -44,12 +49,40 @@ cli_cmd_quit_cbk (struct cli_state *state, struct cli_cmd_word *word,
exit (0);
}
+int
+cli_cmd_display_help (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);
+
+ for (cmd = cli_probe_cmds; cmd->pattern; cmd++)
+ cli_out ("%s - %s", cmd->pattern, cmd->desc);
+
+ for (cmd = cli_log_cmds; cmd->pattern; cmd++)
+ cli_out ("%s - %s", cmd->pattern, cmd->desc);
+
+ for (cmd = cli_misc_cmds; cmd->pattern; cmd++)
+ cli_out ("%s - %s", cmd->pattern, cmd->desc);
+
+ if (!state->rl_enabled)
+ exit (0);
+
+ return 0;
+}
+
struct cli_cmd cli_misc_cmds[] = {
{ "quit",
- cli_cmd_quit_cbk },
+ cli_cmd_quit_cbk,
+ "quit"},
+ { "help",
+ cli_cmd_display_help,
+ "display command options"},
- { NULL, NULL }
+ { NULL, NULL, NULL }
};
@@ -60,7 +93,8 @@ cli_cmd_misc_register (struct cli_state *state)
struct cli_cmd *cmd = NULL;
for (cmd = cli_misc_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk);
+ ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk,
+ cmd->desc);
if (ret)
goto out;
}
diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c
index 2959444fe81..b9acd344a43 100644
--- a/cli/src/cli-cmd-peer.c
+++ b/cli/src/cli-cmd-peer.c
@@ -174,15 +174,18 @@ out:
struct cli_cmd cli_probe_cmds[] = {
{ "peer probe <HOSTNAME> [PORT]",
- cli_cmd_peer_probe_cbk },
+ cli_cmd_peer_probe_cbk,
+ "probe peer specified by <HOSTNAME>"},
{ "peer detach <HOSTNAME>",
- cli_cmd_peer_deprobe_cbk },
+ cli_cmd_peer_deprobe_cbk,
+ "detach peer specified by <HOSTNAME>"},
{ "peer status",
- cli_cmd_peer_status_cbk},
+ cli_cmd_peer_status_cbk,
+ "list status of peers"},
- { NULL, NULL }
+ { NULL, NULL, NULL }
};
@@ -193,7 +196,8 @@ cli_cmd_probe_register (struct cli_state *state)
struct cli_cmd *cmd = NULL;
for (cmd = cli_probe_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk);
+ ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk,
+ cmd->desc);
if (ret)
goto out;
}
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 63c15473072..5a0817e128d 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -437,48 +437,62 @@ cli_cmd_volume_set_transport_cbk (struct cli_state *state,
struct cli_cmd volume_cmds[] = {
{ "volume info [all|<VOLNAME>]",
- cli_cmd_volume_info_cbk },
+ cli_cmd_volume_info_cbk,
+ "list information of all volumes"},
{ "volume create <NEW-VOLNAME> [stripe <COUNT>] [replicate <COUNT>] <NEW-BRICK> ...",
- cli_cmd_volume_create_cbk },
+ cli_cmd_volume_create_cbk,
+ "create a new volume of specified type with mentioned bricks"},
{ "volume delete <VOLNAME>",
- cli_cmd_volume_delete_cbk },
+ cli_cmd_volume_delete_cbk,
+ "delete volume specified by <VOLNAME>"},
{ "volume start <VOLNAME>",
- cli_cmd_volume_start_cbk },
+ cli_cmd_volume_start_cbk,
+ "start volume specified by <VOLNAME>"},
{ "volume stop <VOLNAME>",
- cli_cmd_volume_stop_cbk },
+ cli_cmd_volume_stop_cbk,
+ "stop volume specified by <VOLNAME>"},
{ "volume rename <VOLNAME> <NEW-VOLNAME>",
- cli_cmd_volume_rename_cbk },
+ cli_cmd_volume_rename_cbk,
+ "rename volume <VOLNAME> to <NEW-VOLNAME>"},
{ "volume add-brick <VOLNAME> [(replica <COUNT>)|(stripe <COUNT>)] <NEW-BRICK> ...",
- cli_cmd_volume_add_brick_cbk },
+ cli_cmd_volume_add_brick_cbk,
+ "add brick to volume <VOLNAME>"},
{ "volume remove-brick <VOLNAME> [(replica <COUNT>)|(stripe <COUNT>)] <BRICK> ...",
- cli_cmd_volume_remove_brick_cbk },
+ cli_cmd_volume_remove_brick_cbk,
+ "remove brick from volume <VOLNAME>"},
{ "volume rebalance <VOLNAME> start",
- cli_cmd_volume_defrag_cbk },
+ cli_cmd_volume_defrag_cbk,
+ "start rebalance of volume <VOLNAME>"},
{ "volume rebalance <VOLNAME> stop",
- cli_cmd_volume_defrag_cbk },
+ cli_cmd_volume_defrag_cbk,
+ "stop rebalance of volume <VOLNAME>"},
{ "volume rebalance <VOLNAME> status",
- cli_cmd_volume_defrag_cbk },
+ cli_cmd_volume_defrag_cbk,
+ "rebalance status of volume <VOLNAME>"},
{ "volume replace-brick <VOLNAME> (<BRICK> <NEW-BRICK>)|pause|abort|start|status",
- cli_cmd_volume_replace_brick_cbk },
+ cli_cmd_volume_replace_brick_cbk,
+ "replace-brick operations"},
{ "volume set-transport <VOLNAME> <TRANSPORT-TYPE> [<TRANSPORT-TYPE>] ...",
- cli_cmd_volume_set_transport_cbk },
+ cli_cmd_volume_set_transport_cbk,
+ "set transport type for volume <VOLNAME>"},
{ "volume set <VOLNAME> <KEY> <VALUE>",
- cli_cmd_volume_set_cbk },
+ cli_cmd_volume_set_cbk,
+ "set options for volume <VOLNAME>"},
- { NULL, NULL }
+ { NULL, NULL, NULL }
};
@@ -489,7 +503,8 @@ cli_cmd_volume_register (struct cli_state *state)
struct cli_cmd *cmd = NULL;
for (cmd = volume_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk);
+ ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk,
+ cmd->desc);
if (ret)
goto out;
}
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index 4353cb6e7b6..d7a4fcd837a 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -50,6 +50,9 @@ cli_cmd_needs_connection (struct cli_cmd_word *word)
if (!strcasecmp ("quit", word->word))
return _gf_false;
+ if (!strcasecmp ("help", word->word))
+ return _gf_false;
+
return _gf_true;
}
diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h
index d62309de23c..b325cfdfccc 100644
--- a/cli/src/cli-cmd.h
+++ b/cli/src/cli-cmd.h
@@ -30,6 +30,7 @@
struct cli_cmd {
const char *pattern;
cli_cmd_cbk_t *cbk;
+ const char *desc;
};
int cli_cmd_volume_register (struct cli_state *state);
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 9efabfe589d..9bc0b50946a 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -56,6 +56,7 @@ struct cli_cmd_word {
cli_cmd_filler_t *filler;
cli_cmd_match_t *match;
cli_cmd_cbk_t *cbkfn;
+ const char *desc;
int nextwords_cnt;
struct cli_cmd_word **nextwords;
@@ -134,7 +135,7 @@ typedef ssize_t (*cli_serialize_t) (struct iovec outmsg, void *args);
extern struct cli_state *global_state; /* use only in readline callback */
int cli_cmd_register (struct cli_cmd_tree *tree, const char *template,
- cli_cmd_cbk_t cbk);
+ cli_cmd_cbk_t cbk, const char *desc);
int cli_cmds_register (struct cli_state *state);
int cli_input_init (struct cli_state *state);
diff --git a/cli/src/registry.c b/cli/src/registry.c
index 0ced00787c8..f7e366fd66c 100644
--- a/cli/src/registry.c
+++ b/cli/src/registry.c
@@ -318,7 +318,8 @@ 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)
+cli_cmd_ingest (struct cli_cmd_tree *tree, char **tokens, cli_cmd_cbk_t *cbkfn,
+ const char *desc)
{
int ret = 0;
char **tokenp = NULL;
@@ -349,6 +350,7 @@ cli_cmd_ingest (struct cli_cmd_tree *tree, char **tokens, cli_cmd_cbk_t *cbkfn)
}
word->cbkfn = cbkfn;
+ word->desc = desc;
/* end of static strings in command template */
@@ -360,7 +362,7 @@ cli_cmd_ingest (struct cli_cmd_tree *tree, char **tokens, cli_cmd_cbk_t *cbkfn)
int
cli_cmd_register (struct cli_cmd_tree *tree, const char *template,
- cli_cmd_cbk_t cbk)
+ cli_cmd_cbk_t cbk, const char *desc)
{
char **tokens = NULL;
int ret = 0;
@@ -372,7 +374,7 @@ cli_cmd_register (struct cli_cmd_tree *tree, const char *template,
if (!tokens)
return -1;
- ret = cli_cmd_ingest (tree, tokens, cbk);
+ ret = cli_cmd_ingest (tree, tokens, cbk, desc);
if (ret)
goto err;