Browse Source

Merge pull request #6059 from jlamillan/honor_global_output

etcdctl: Add support for formating output of key related commands
Gyu-Ho Lee 9 years ago
parent
commit
1153350a95

+ 4 - 1
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")
 	ttl := c.Int("ttl")
 
 
 	ctx, cancel := contextWithTotalTimeout(c)
 	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()
 	cancel()
 	if err != nil {
 	if err != nil {
 		handleError(ExitServerError, err)
 		handleError(ExitServerError, err)
 	}
 	}
+	if c.GlobalString("output") != "simple" {
+		printResponseKey(resp, c.GlobalString("output"))
+	}
 }
 }

+ 1 - 2
etcdctl/ctlv2/command/rm_command.go

@@ -57,8 +57,7 @@ func rmCommandFunc(c *cli.Context, ki client.KeysAPI) {
 	if err != nil {
 	if err != nil {
 		handleError(ExitServerError, err)
 		handleError(ExitServerError, err)
 	}
 	}
-
-	if !resp.Node.Dir {
+	if !resp.Node.Dir || c.GlobalString("output") != "simple" {
 		printResponseKey(resp, c.GlobalString("output"))
 		printResponseKey(resp, c.GlobalString("output"))
 	}
 	}
 }
 }

+ 1 - 1
etcdctl/ctlv2/command/rmdir_command.go

@@ -48,7 +48,7 @@ func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) {
 		handleError(ExitServerError, err)
 		handleError(ExitServerError, err)
 	}
 	}
 
 
-	if !resp.Node.Dir {
+	if !resp.Node.Dir || c.GlobalString("output") != "simple" {
 		printResponseKey(resp, c.GlobalString("output"))
 		printResponseKey(resp, c.GlobalString("output"))
 	}
 	}
 }
 }

+ 4 - 1
etcdctl/ctlv2/command/update_dir_command.go

@@ -46,9 +46,12 @@ func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) {
 	key := c.Args()[0]
 	key := c.Args()[0]
 	ttl := c.Int("ttl")
 	ttl := c.Int("ttl")
 	ctx, cancel := contextWithTotalTimeout(c)
 	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()
 	cancel()
 	if err != nil {
 	if err != nil {
 		handleError(ExitServerError, err)
 		handleError(ExitServerError, err)
 	}
 	}
+	if c.GlobalString("output") != "simple" {
+		printResponseKey(resp, c.GlobalString("output"))
+	}
 }
 }