diff --git a/changelog/21546.txt b/changelog/21546.txt new file mode 100644 index 0000000000..8eaf53ed39 --- /dev/null +++ b/changelog/21546.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Avoid printing "Success" message when `-field` flag is provided during a `vault write`. +``` diff --git a/command/write.go b/command/write.go index 85c251d1f5..cd3301b8f2 100644 --- a/command/write.go +++ b/command/write.go @@ -155,7 +155,8 @@ func handleWriteSecretOutput(c *BaseCommand, path string, secret *api.Secret, er } if secret == nil { // Don't output anything unless using the "table" format - if Format(c.UI) == "table" { + // and even then, don't output anything if a specific field was requested + if c.flagField == "" && Format(c.UI) == "table" { c.UI.Info(fmt.Sprintf("Success! Data written to: %s", path)) } return 0 diff --git a/command/write_test.go b/command/write_test.go index c7c6f68da0..24521311ba 100644 --- a/command/write_test.go +++ b/command/write_test.go @@ -118,6 +118,30 @@ func TestWriteCommand_Run(t *testing.T) { }) } + // If we ask for a field and get an empty result, do not output "Success!" or anything else + t.Run("field_from_nothing", func(t *testing.T) { + t.Parallel() + + client, closer := testVaultServer(t) + defer closer() + + ui, cmd := testWriteCommand(t) + cmd.client = client + + code := cmd.Run([]string{ + "-field", "somefield", + "secret/write/foo", "foo=bar", + }) + if exp := 0; code != exp { + t.Fatalf("expected %d to be %d: %q", code, exp, ui.ErrorWriter.String()) + } + + combined := ui.OutputWriter.String() + ui.ErrorWriter.String() + if combined != "" { + t.Errorf("expected %q to be empty", combined) + } + }) + t.Run("force", func(t *testing.T) { t.Parallel() diff --git a/website/content/docs/commands/login.mdx b/website/content/docs/commands/login.mdx index 18bc950d26..58070604b3 100644 --- a/website/content/docs/commands/login.mdx +++ b/website/content/docs/commands/login.mdx @@ -127,9 +127,9 @@ flags](/vault/docs/commands) included on all commands. ### Output options -- `-field` `(string: "")` - Print only the field with the given name. Specifying - this option will take precedence over other formatting directives. The result - will not have a trailing newline making it ideal for piping to other processes. +- `-field` `(string: "")` - Print only the field with the given name, in the format + specified in the `-format` directive. The result will not have a trailing + newline making it ideal for piping to other processes. - `-format` `(string: "table")` - Print the output in the given format. Valid formats are "table", "json", or "yaml". This can also be specified via the diff --git a/website/content/docs/commands/patch.mdx b/website/content/docs/commands/patch.mdx index 8270364852..882f64025d 100644 --- a/website/content/docs/commands/patch.mdx +++ b/website/content/docs/commands/patch.mdx @@ -72,9 +72,9 @@ flags](/vault/docs/commands) included on all commands. ### Output options -- `-field` `(string: "")` - Print only the field with the given name. Specifying - this option will take precedence over other formatting directives. The result - will not have a trailing newline making it ideal for piping to other processes. +- `-field` `(string: "")` - Print only the field with the given name, in the format + specified in the `-format` directive. The result will not have a trailing + newline making it ideal for piping to other processes. - `-format` `(string: "table")` - Print the output in the given format. Valid formats are "table", "json", or "yaml". This can also be specified via the diff --git a/website/content/docs/commands/read.mdx b/website/content/docs/commands/read.mdx index 36f7b9c848..be1b5a9eb8 100644 --- a/website/content/docs/commands/read.mdx +++ b/website/content/docs/commands/read.mdx @@ -65,9 +65,9 @@ flags](/vault/docs/commands) included on all commands. ### Output options -- `-field` `(string: "")` - Print only the field with the given name. Specifying - this option will take precedence over other formatting directives. The result - will not have a trailing newline making it ideal for piping to other processes. +- `-field` `(string: "")` - Print only the field with the given name, in the format + specified in the `-format` directive. The result will not have a trailing + newline making it ideal for piping to other processes. - `-format` `(string: "table")` - Print the output in the given format. Valid formats are "table", "json", "yaml", or "raw". This can also be specified diff --git a/website/content/docs/commands/ssh.mdx b/website/content/docs/commands/ssh.mdx index a0d8291f88..9395ed1981 100644 --- a/website/content/docs/commands/ssh.mdx +++ b/website/content/docs/commands/ssh.mdx @@ -54,9 +54,9 @@ flags](/vault/docs/commands) included on all commands. ### Output options -- `-field` `(string: "")` - Print only the field with the given name. Specifying - this option will take precedence over other formatting directives. The result - will not have a trailing newline making it ideal for piping to other processes. +- `-field` `(string: "")` - Print only the field with the given name, in the format + specified in the `-format` directive. The result will not have a trailing + newline making it ideal for piping to other processes. - `-format` `(string: "table")` - Print the output in the given format. Valid formats are "table", "json", or "yaml". This can also be specified via the diff --git a/website/content/docs/commands/unwrap.mdx b/website/content/docs/commands/unwrap.mdx index 2432d8dd3d..b53caa6475 100644 --- a/website/content/docs/commands/unwrap.mdx +++ b/website/content/docs/commands/unwrap.mdx @@ -36,9 +36,9 @@ flags](/vault/docs/commands) included on all commands. ### Output options -- `-field` `(string: "")` - Print only the field with the given name. Specifying - this option will take precedence over other formatting directives. The result - will not have a trailing newline making it ideal for piping to other processes. +- `-field` `(string: "")` - Print only the field with the given name, in the format + specified in the `-format` directive. The result will not have a trailing + newline making it ideal for piping to other processes. - `-format` `(string: "table")` - Print the output in the given format. Valid formats are "table", "json", or "yaml". This can also be specified via the diff --git a/website/content/docs/commands/write.mdx b/website/content/docs/commands/write.mdx index 989297f298..b73a77a47d 100644 --- a/website/content/docs/commands/write.mdx +++ b/website/content/docs/commands/write.mdx @@ -106,9 +106,9 @@ flags](/vault/docs/commands) included on all commands. ### Output options -- `-field` `(string: "")` - Print only the field with the given name. Specifying - this option will take precedence over other formatting directives. The result - will not have a trailing newline making it ideal for piping to other processes. +- `-field` `(string: "")` - Print only the field with the given name, in the format + specified in the `-format` directive. The result will not have a trailing + newline making it ideal for piping to other processes. - `-format` `(string: "table")` - Print the output in the given format. Valid formats are "table", "json", or "yaml". This can also be specified via the