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.
This commit is contained in:
Chris Piraino 2020-06-29 15:47:40 -05:00 committed by GitHub
parent 8335a15b34
commit ea683ebb6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 7 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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)