From 2fb72029eff95d0d725487aad8b36f88fa40b4a8 Mon Sep 17 00:00:00 2001 From: "jesse.millan" Date: Tue, 19 Jul 2016 16:13:24 -0700 Subject: [PATCH] etcdctl: Add support for formating output of ls command in json The ls command will check for and honor json or extended output formats. Fixes #5993 --- etcdctl/ctlv2/command/ls_command.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/etcdctl/ctlv2/command/ls_command.go b/etcdctl/ctlv2/command/ls_command.go index 2c43256fc..d5a8ede02 100644 --- a/etcdctl/ctlv2/command/ls_command.go +++ b/etcdctl/ctlv2/command/ls_command.go @@ -63,11 +63,16 @@ func lsCommandFunc(c *cli.Context, ki client.KeysAPI) { // printLs writes a response out in a manner similar to the `ls` command in unix. // Non-empty directories list their contents and files list their name. func printLs(c *cli.Context, resp *client.Response) { - if !resp.Node.Dir { - fmt.Println(resp.Node.Key) - } - for _, node := range resp.Node.Nodes { - rPrint(c, node) + if c.GlobalString("output") == "simple" { + if !resp.Node.Dir { + fmt.Println(resp.Node.Key) + } + for _, node := range resp.Node.Nodes { + rPrint(c, node) + } + } else { + // user wants JSON or extended output + printResponseKey(resp, c.GlobalString("output")) } }