summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorVijaikumar M <vmallika@redhat.com>2014-06-20 15:40:46 +0530
committerKaushal M <kaushal@redhat.com>2014-07-02 04:04:25 -0700
commitca6980d0828a6e7f38d7638a3b99db5d9be36260 (patch)
tree7f00b6149b93cde1cf8987d2040393d8ad31c964 /cli
parent0e6cd39d55be3f4397772dcd75b0b59daedc8f55 (diff)
cli: Format the hostname column properly in the 'pool list' o/p
In the pool list output, if the hostname is lengthier, then the indentation was not proper. Solution: 1) get the full list of hostnames first (prior to display) 2) Determine the maximum length of the hostname strings from that 3) Create an appropriate display padding amount, using the length from (2) Change-Id: Icc3724975a5e30b02b8e06db709930cbac5e0875 BUG: 1028871 Signed-off-by: Vijaikumar M <vmallika@redhat.com> Reviewed-on: http://review.gluster.org/8127 Tested-by: Justin Clift <justin@gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> Reviewed-by: Avra Sengupta <asengupt@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-rpc-ops.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 9d64917e3b7..c077622c0f1 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -265,17 +265,34 @@ out:
int
gf_cli_output_pool_list (dict_t *dict, int count)
{
- int ret = -1;
- char *uuid_buf = NULL;
- char *hostname_buf = NULL;
- int32_t i = 1;
- char key[256] = {0,};
- int32_t connected = 0;
+ int ret = -1;
+ char *uuid_buf = NULL;
+ char *hostname_buf = NULL;
+ int32_t hostname_len = 8; /*min len 8 chars*/
+ int32_t i = 1;
+ char key[256] = {0,};
+ int32_t connected = 0;
char *connected_str = NULL;
- if (count >= 1)
- cli_out ("UUID\t\t\t\t\tHostname\tState");
+ if (count <= 0)
+ goto out;
+
+ while (i <= count) {
+ snprintf (key, 256, "friend%d.hostname", i);
+ ret = dict_get_str (dict, key, &hostname_buf);
+ if (ret)
+ goto out;
+
+ ret = strlen(hostname_buf);
+ if (ret > hostname_len)
+ hostname_len = ret;
+ i++;
+ }
+
+ cli_out ("UUID\t\t\t\t\t%-*s\tState", hostname_len, "Hostname");
+
+ i = 1;
while ( i <= count) {
snprintf (key, 256, "friend%d.uuid", i);
ret = dict_get_str (dict, key, &uuid_buf);
@@ -296,7 +313,7 @@ gf_cli_output_pool_list (dict_t *dict, int count)
else
connected_str = "Disconnected";
- cli_out ("%s\t%-9s\t%s ", uuid_buf, hostname_buf,
+ cli_out ("%s\t%-*s\t%s ", uuid_buf, hostname_len, hostname_buf,
connected_str);
i++;
}