diff --git a/command/kv_put.go b/command/kv_put.go index 4c214a665..f5e1fa5de 100644 --- a/command/kv_put.go +++ b/command/kv_put.go @@ -228,15 +228,15 @@ func (c *KVPutCommand) dataFromArgs(args []string) (string, string, error) { } return key, string(data), nil case '-': - var b bytes.Buffer if len(data) > 1 { return key, data, nil } else { + var b bytes.Buffer if _, err := io.Copy(&b, stdin); err != nil { return "", "", fmt.Errorf("Failed to read stdin: %s", err) } + return key, b.String(), nil } - return key, b.String(), nil default: return key, data, nil } diff --git a/command/kv_put_test.go b/command/kv_put_test.go index 8239809cc..5b84a68b3 100644 --- a/command/kv_put_test.go +++ b/command/kv_put_test.go @@ -194,6 +194,34 @@ func TestKVPutCommand_Stdin(t *testing.T) { } } +func TestKVPutCommand_NegativeVal(t *testing.T) { + srv, client := testAgentWithAPIClient(t) + defer srv.Shutdown() + waitForLeader(t, srv.httpAddr) + + ui := new(cli.MockUi) + c := &KVPutCommand{Ui: ui} + + args := []string{ + "-http-addr=" + srv.httpAddr, + "foo", "-2", + } + + code := c.Run(args) + if code != 0 { + t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) + } + + data, _, err := client.KV().Get("foo", nil) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(data.Value, []byte("-2")) { + t.Errorf("bad: %#v", data.Value) + } +} + func TestKVPutCommand_Flags(t *testing.T) { srv, client := testAgentWithAPIClient(t) defer srv.Shutdown()