From 4b19d33d34ce56c0b182d353e223e570359815ac Mon Sep 17 00:00:00 2001 From: Chris Piraino Date: Mon, 29 Jun 2020 15:47:40 -0500 Subject: [PATCH] cli: Output message on success when writing/deleting entries (#7806) This provides a user with a better experience, knowing that the command worked appropriately. The output of the write/delete CLI commands are not going to be used in a bash script, in fact previously a success provided no ouput, so we do not have to worry about spurious text being injected into bash pipelines. --- command/config/delete/config_delete.go | 4 ++-- command/config/delete/config_delete_test.go | 3 ++- command/config/read/config_read.go | 2 +- command/config/write/config_write.go | 6 +++--- command/config/write/config_write_test.go | 4 ++++ 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/command/config/delete/config_delete.go b/command/config/delete/config_delete.go index 876092608f..41eef8b156 100644 --- a/command/config/delete/config_delete.go +++ b/command/config/delete/config_delete.go @@ -58,11 +58,11 @@ func (c *cmd) Run(args []string) int { _, err = client.ConfigEntries().Delete(c.kind, c.name, nil) if err != nil { - c.UI.Error(fmt.Sprintf("Error deleting config entry %q / %q: %v", c.kind, c.name, err)) + c.UI.Error(fmt.Sprintf("Error deleting config entry %s/%s: %v", c.kind, c.name, err)) return 1 } - // TODO (mkeeler) should we output anything when successful + c.UI.Info(fmt.Sprintf("Config entry deleted: %s/%s", c.kind, c.name)) return 0 } diff --git a/command/config/delete/config_delete_test.go b/command/config/delete/config_delete_test.go index 8a3cbde6fb..c1f7951a5a 100644 --- a/command/config/delete/config_delete_test.go +++ b/command/config/delete/config_delete_test.go @@ -40,7 +40,8 @@ func TestConfigDelete(t *testing.T) { code := c.Run(args) require.Equal(t, 0, code) - require.Empty(t, ui.OutputWriter.String()) + require.Contains(t, ui.OutputWriter.String(), + "Config entry deleted: service-defaults/web") require.Empty(t, ui.ErrorWriter.String()) entry, _, err := client.ConfigEntries().Get(api.ServiceDefaults, "web", nil) diff --git a/command/config/read/config_read.go b/command/config/read/config_read.go index acba927abe..399e68c28f 100644 --- a/command/config/read/config_read.go +++ b/command/config/read/config_read.go @@ -61,7 +61,7 @@ func (c *cmd) Run(args []string) int { entry, _, err := client.ConfigEntries().Get(c.kind, c.name, nil) if err != nil { - c.UI.Error(fmt.Sprintf("Error reading config entry %q / %q: %v", c.kind, c.name, err)) + c.UI.Error(fmt.Sprintf("Error reading config entry %s/%s: %v", c.kind, c.name, err)) return 1 } diff --git a/command/config/write/config_write.go b/command/config/write/config_write.go index 8691ab8eaf..42a4789e64 100644 --- a/command/config/write/config_write.go +++ b/command/config/write/config_write.go @@ -85,16 +85,16 @@ func (c *cmd) Run(args []string) int { written, _, err = entries.Set(entry, nil) } if err != nil { - c.UI.Error(fmt.Sprintf("Error writing config entry %q / %q: %v", entry.GetKind(), entry.GetName(), err)) + c.UI.Error(fmt.Sprintf("Error writing config entry %s/%s: %v", entry.GetKind(), entry.GetName(), err)) return 1 } if !written { - c.UI.Error(fmt.Sprintf("Config entry %q / %q not updated", entry.GetKind(), entry.GetName())) + c.UI.Error(fmt.Sprintf("Config entry not updated: %s/%s", entry.GetKind(), entry.GetName())) return 1 } - // TODO (mkeeler) should we output anything when successful + c.UI.Info(fmt.Sprintf("Config entry written: %s/%s", entry.GetKind(), entry.GetName())) return 0 } diff --git a/command/config/write/config_write_test.go b/command/config/write/config_write_test.go index 970709adb7..e111f323c6 100644 --- a/command/config/write/config_write_test.go +++ b/command/config/write/config_write_test.go @@ -48,6 +48,8 @@ func TestConfigWrite(t *testing.T) { code := c.Run(args) require.Empty(t, ui.ErrorWriter.String()) + require.Contains(t, ui.OutputWriter.String(), + `Config entry written: service-defaults/web`) require.Equal(t, 0, code) entry, _, err := client.ConfigEntries().Get("service-defaults", "web", nil) @@ -85,6 +87,8 @@ func TestConfigWrite(t *testing.T) { code := c.Run(args) require.Empty(t, ui.ErrorWriter.String()) + require.Contains(t, ui.OutputWriter.String(), + `Config entry written: proxy-defaults/global`) require.Equal(t, 0, code) entry, _, err := client.ConfigEntries().Get(api.ProxyDefaults, api.ProxyConfigGlobal, nil)