From 205f10aeb6d7a2869d4da16131cccb77ba5289e2 Mon Sep 17 00:00:00 2001 From: "jesse.millan" Date: Wed, 27 Jul 2016 14:17:19 -0700 Subject: [PATCH] etcdctl: Add support for formating output of key related commands All v2 key and dir related commands will now honor the global format option if it was specified. Otherwise, the output will remain the same. --- etcdctl/ctlv2/command/mkdir_command.go | 5 ++++- etcdctl/ctlv2/command/rm_command.go | 3 +-- etcdctl/ctlv2/command/rmdir_command.go | 2 +- etcdctl/ctlv2/command/update_dir_command.go | 5 ++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/etcdctl/ctlv2/command/mkdir_command.go b/etcdctl/ctlv2/command/mkdir_command.go index ec848bf11..7d2c6779c 100644 --- a/etcdctl/ctlv2/command/mkdir_command.go +++ b/etcdctl/ctlv2/command/mkdir_command.go @@ -48,9 +48,12 @@ func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevEx ttl := c.Int("ttl") ctx, cancel := contextWithTotalTimeout(c) - _, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist}) + resp, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist}) cancel() if err != nil { handleError(ExitServerError, err) } + if c.GlobalString("output") != "simple" { + printResponseKey(resp, c.GlobalString("output")) + } } diff --git a/etcdctl/ctlv2/command/rm_command.go b/etcdctl/ctlv2/command/rm_command.go index c4941c364..6c2104480 100644 --- a/etcdctl/ctlv2/command/rm_command.go +++ b/etcdctl/ctlv2/command/rm_command.go @@ -57,8 +57,7 @@ func rmCommandFunc(c *cli.Context, ki client.KeysAPI) { if err != nil { handleError(ExitServerError, err) } - - if !resp.Node.Dir { + if !resp.Node.Dir || c.GlobalString("output") != "simple" { printResponseKey(resp, c.GlobalString("output")) } } diff --git a/etcdctl/ctlv2/command/rmdir_command.go b/etcdctl/ctlv2/command/rmdir_command.go index 1078ee87a..9a685118d 100644 --- a/etcdctl/ctlv2/command/rmdir_command.go +++ b/etcdctl/ctlv2/command/rmdir_command.go @@ -48,7 +48,7 @@ func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) { handleError(ExitServerError, err) } - if !resp.Node.Dir { + if !resp.Node.Dir || c.GlobalString("output") != "simple" { printResponseKey(resp, c.GlobalString("output")) } } diff --git a/etcdctl/ctlv2/command/update_dir_command.go b/etcdctl/ctlv2/command/update_dir_command.go index cdb9333b9..650674a6f 100644 --- a/etcdctl/ctlv2/command/update_dir_command.go +++ b/etcdctl/ctlv2/command/update_dir_command.go @@ -46,9 +46,12 @@ func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) { key := c.Args()[0] ttl := c.Int("ttl") ctx, cancel := contextWithTotalTimeout(c) - _, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist}) + resp, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist}) cancel() if err != nil { handleError(ExitServerError, err) } + if c.GlobalString("output") != "simple" { + printResponseKey(resp, c.GlobalString("output")) + } }