diff options
author | Mohamed Ashiq <mliyazud@redhat.com> | 2015-07-15 14:19:49 +0530 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2015-11-02 02:03:28 -0800 |
commit | 0b6f0e09715fb2ba8f86bd80b05d552ae75aeda9 (patch) | |
tree | 6186add585892688da794b475de3c11b218d32bd /cli | |
parent | 43d819bc99874ee900a03a27c79cd8523423d9b6 (diff) |
cli : 'gluster volume help' output sorted alphabetically
'gluster volume help' output is not sorted alphabetically.
This makes little harder for the user to search or get to know of
few gluster volume commands usage just from gluster cli.
Backport of http://review.gluster.org/11663
Cherry picked from 323e71617fee5020324540776d0d4469577f0afe
Change-Id: I855da2e4748a5c2ff3be319c50fa9548d676ee8a
BUG: 1276208
Signed-off-by: Mohamed Ashiq <mliyazud@redhat.com>
>Reviewed-on: http://review.gluster.org/11663
>Tested-by: Gluster Build System <jenkins@build.gluster.com>
>Reviewed-by: Manikandan Selvaganesh <mselvaga@redhat.com>
>Reviewed-by: Anand Nekkunti <anekkunt@redhat.com>
Reviewed-on: http://review.gluster.org/12452
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Nekkunti <anekkunt@redhat.com>
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 9b71821b00c..dc28b74dea5 100644 --- a/cli/src/cli-cmd-global.c +++ b/cli/src/cli-cmd-global.c @@ -58,11 +58,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 94f059df623..6568c2a1fcb 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -274,12 +274,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 2716dd094af..c070bb85dec 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -20,6 +20,7 @@ #include "cli.h" #include "cli-cmd.h" +#include "cli-mem-types.h" extern rpc_clnt_prog_t *cli_rpc_prog; @@ -135,12 +136,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 690a104183a..70fa5e65f93 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -577,11 +577,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 670a597a8f7..64f1d9d1b38 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -2800,12 +2800,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 5ea1edc9cac..12629b7b5f1 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -395,3 +395,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 3a689c45b88..2a4c711c7d4 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -110,6 +110,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 }; |