Merge pull request #3175 from xiang90/2.2-ctl-bug

etcdctl: fix exec watch command
This commit is contained in:
Xiang Li 2015-07-23 14:37:38 +08:00
commit 58bc617dd0

View File

@ -51,21 +51,35 @@ func execWatchCommandFunc(c *cli.Context, ki client.KeysAPI) {
handleError(ExitBadArgs, errors.New("key and command to exec required"))
}
key := args[argslen-1]
cmdArgs := args[:argslen-1]
var (
key string
cmdArgs []string
)
foundSep := false
for i := range args {
if args[i] == "--" && i != 0 {
foundSep = true
break
}
}
if foundSep {
key = args[0]
cmdArgs = args[2:]
} else {
// If no flag is parsed, the order of key and cmdArgs will be switched and
// args will not contain `--`.
key = args[argslen-1]
cmdArgs = args[:argslen-1]
}
index := 0
if c.Int("after-index") != 0 {
index = c.Int("after-index") + 1
key = args[0]
cmdArgs = args[2:]
}
recursive := c.Bool("recursive")
if recursive != false {
key = args[0]
cmdArgs = args[2:]
}
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)