diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-global.c | 15 | ||||
-rw-r--r-- | cli/src/cli-cmd-peer.c | 12 | ||||
-rw-r--r-- | cli/src/cli-cmd-snapshot.c | 20 | ||||
-rw-r--r-- | cli/src/cli-cmd-system.c | 14 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 16 | ||||
-rw-r--r-- | cli/src/cli-cmd.c | 25 | ||||
-rw-r--r-- | cli/src/cli-cmd.h | 4 | ||||
-rw-r--r-- | cli/src/cli-mem-types.h | 1 |
8 files changed, 89 insertions, 18 deletions
diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c index 3c526f8a828..53ee0ab2517 100644 --- a/cli/src/cli-cmd-global.c +++ b/cli/src/cli-cmd-global.c @@ -53,11 +53,20 @@ cli_cmd_global_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount) { struct cli_cmd *cmd = NULL; + struct cli_cmd *global_cmd = NULL; + int count = 0; - for (cmd = global_cmds; cmd->pattern; cmd++) - if (_gf_false == cmd->disable) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + cmd = GF_CALLOC (1, sizeof (global_cmds), cli_mt_cli_cmd); + memcpy (cmd, global_cmds, sizeof (global_cmds)); + count = (sizeof (global_cmds) / sizeof (struct cli_cmd)); + cli_cmd_sort (cmd, count); + for (global_cmd = cmd; global_cmd->pattern; global_cmd++) + if (_gf_false == global_cmd->disable) + cli_out ("%s - %s", global_cmd->pattern, + global_cmd->desc); + + GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index 0ca31028211..d6b4ab147a4 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -269,12 +269,20 @@ 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; + struct cli_cmd *probe_cmd = NULL; + int count = 0; + cmd = GF_CALLOC (1, sizeof (cli_probe_cmds), cli_mt_cli_cmd); + memcpy (cmd, cli_probe_cmds, sizeof (cli_probe_cmds)); + count = (sizeof (cli_probe_cmds) / sizeof (struct cli_cmd)); + cli_cmd_sort (cmd, count); - for (cmd = cli_probe_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + for (probe_cmd = cmd; probe_cmd->pattern; probe_cmd++) + cli_out ("%s - %s", probe_cmd->pattern, probe_cmd->desc); + + GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index 80ab2b0f211..e79128c5a59 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -15,6 +15,7 @@ #include "cli.h" #include "cli-cmd.h" +#include "cli-mem-types.h" extern rpc_clnt_prog_t *cli_rpc_prog; @@ -130,12 +131,19 @@ cli_cmd_snapshot_help_cbk (struct cli_state *state, const char **words, int wordcount) { - struct cli_cmd *cmd = NULL; - - for (cmd = snapshot_cmds; cmd->pattern; cmd++) - if (_gf_false == cmd->disable) - cli_out ("%s - %s", cmd->pattern, cmd->desc); - + struct cli_cmd *cmd = NULL; + struct cli_cmd *snap_cmd = NULL; + int count = 0; + + cmd = GF_CALLOC (1, sizeof (snapshot_cmds), cli_mt_cli_cmd); + memcpy (cmd, snapshot_cmds, sizeof (snapshot_cmds)); + count = (sizeof (snapshot_cmds) / sizeof (struct cli_cmd)); + cli_cmd_sort (cmd, count); + + for (snap_cmd = cmd; snap_cmd->pattern; snap_cmd++) + if (_gf_false == snap_cmd->disable) + cli_out ("%s - %s", snap_cmd->pattern, snap_cmd->desc); + GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c index d71f622ba11..89d7d23187e 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -572,11 +572,19 @@ int cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount) { - struct cli_cmd *cmd = NULL; + struct cli_cmd *cmd = NULL; + struct cli_cmd *system_cmd = NULL; + int count = 0; + + cmd = GF_CALLOC (1, sizeof (cli_system_cmds), cli_mt_cli_cmd); + memcpy (cmd, cli_system_cmds, sizeof (cli_system_cmds)); + count = (sizeof (cli_system_cmds) / sizeof (struct cli_cmd)); + cli_cmd_sort (cmd, count); - for (cmd = cli_system_cmds; cmd->pattern; cmd++) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + for (system_cmd = cmd; system_cmd->pattern; system_cmd++) + cli_out ("%s - %s", system_cmd->pattern, system_cmd->desc); + GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 4cff9e9e7c0..25133f1156a 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -2797,12 +2797,20 @@ 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; + struct cli_cmd *cmd = NULL; + struct cli_cmd *vol_cmd = NULL; + int count = 0; - for (cmd = volume_cmds; cmd->pattern; cmd++) - if (_gf_false == cmd->disable) - cli_out ("%s - %s", cmd->pattern, cmd->desc); + cmd = GF_CALLOC (1, sizeof (volume_cmds), cli_mt_cli_cmd); + memcpy (cmd, volume_cmds, sizeof (volume_cmds)); + count = (sizeof (volume_cmds) / sizeof (struct cli_cmd)); + cli_cmd_sort (cmd, count); + for (vol_cmd = cmd; vol_cmd->pattern; vol_cmd++) + if (_gf_false == vol_cmd->disable) + cli_out ("%s - %s", vol_cmd->pattern, vol_cmd->desc); + + GF_FREE (cmd); return 0; } diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index 99448fcae56..a1e4e909a0d 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -390,3 +390,28 @@ cli_cmd_submit (struct rpc_clnt* rpc, void *req, call_frame_t *frame, gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); return ret; } + +int +cli_cmd_pattern_cmp (void *a, void *b) +{ + struct cli_cmd *ia = NULL; + struct cli_cmd *ib = NULL; + int ret = 0; + + ia = a; + ib = b; + if (strcmp (ia->pattern, ib->pattern) > 0) + ret = 1; + else if (strcmp (ia->pattern, ib->pattern) < 0) + ret = -1; + else + ret = 0; + return ret; +} + +void +cli_cmd_sort (struct cli_cmd *cmd, int count) +{ + gf_array_insertionsort (cmd, 1, count - 2, sizeof(struct cli_cmd), + cli_cmd_pattern_cmp); +} diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h index 27f385fab85..2f96bdda2ff 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -105,6 +105,10 @@ cli_cmd_submit (struct rpc_clnt *rpc, void *req, call_frame_t *frame, int procnum, struct iobref *iobref, xlator_t *this, fop_cbk_fn_t cbkfn, xdrproc_t xdrproc); +int cli_cmd_pattern_cmp (void *a, void *b); + +void cli_cmd_sort (struct cli_cmd *cmd, int count); + gf_answer_t cli_cmd_get_confirmation (struct cli_state *state, const char *question); int cli_cmd_sent_status_get (int *status); diff --git a/cli/src/cli-mem-types.h b/cli/src/cli-mem-types.h index 09fcb639bd0..5468b25cc0c 100644 --- a/cli/src/cli-mem-types.h +++ b/cli/src/cli-mem-types.h @@ -23,6 +23,7 @@ enum cli_mem_types_ { cli_mt_cli_local_t, cli_mt_cli_get_vol_ctx_t, cli_mt_append_str, + cli_mt_cli_cmd, cli_mt_end }; |