Audit listing with format json returns json, not a string (#6776)

* Audit listing with format json returns json, not a string

Fixes #6775

* list, kv list and namespace list with format json returns json, not a string

* Changed audit list return code to 2 which aligns with other list commands return codes
This commit is contained in:
Jeff Mitchell 2019-06-04 13:36:34 -04:00 committed by Brian Kassouf
parent 5f7321dcc7
commit 38c0a9d7a5
4 changed files with 35 additions and 8 deletions

View File

@ -94,13 +94,13 @@ func (c *AuditListCommand) Run(args []string) int {
return 2
}
if len(audits) == 0 {
c.UI.Output(fmt.Sprintf("No audit devices are enabled."))
return 0
}
switch Format(c.UI) {
case "table":
if len(audits) == 0 {
c.UI.Output(fmt.Sprintf("No audit devices are enabled."))
return 2
}
if c.flagDetailed {
c.UI.Output(tableOutput(c.detailedAudits(audits), nil))
return 0

View File

@ -93,6 +93,15 @@ func (c *KVListCommand) Run(args []string) int {
c.UI.Error(fmt.Sprintf("Error listing %s: %s", path, err))
return 2
}
_, ok := extractListData(secret)
if Format(c.UI) != "table" {
if secret == nil || secret.Data == nil || !ok {
OutputData(c.UI, map[string]interface{}{})
return 2
}
}
if secret == nil || secret.Data == nil {
c.UI.Error(fmt.Sprintf("No value found at %s", path))
return 2
@ -103,7 +112,7 @@ func (c *KVListCommand) Run(args []string) int {
return OutputSecret(c.UI, secret)
}
if _, ok := extractListData(secret); !ok {
if !ok {
c.UI.Error(fmt.Sprintf("No entries found at %s", path))
return 2
}

View File

@ -82,6 +82,15 @@ func (c *ListCommand) Run(args []string) int {
c.UI.Error(fmt.Sprintf("Error listing %s: %s", path, err))
return 2
}
_, ok := extractListData(secret)
if Format(c.UI) != "table" {
if secret == nil || secret.Data == nil || !ok {
OutputData(c.UI, map[string]interface{}{})
return 2
}
}
if secret == nil {
c.UI.Error(fmt.Sprintf("No value found at %s", path))
return 2
@ -97,7 +106,7 @@ func (c *ListCommand) Run(args []string) int {
return OutputSecret(c.UI, secret)
}
if _, ok := extractListData(secret); !ok {
if !ok {
c.UI.Error(fmt.Sprintf("No entries found at %s", path))
return 2
}

View File

@ -71,6 +71,15 @@ func (c *NamespaceListCommand) Run(args []string) int {
c.UI.Error(fmt.Sprintf("Error listing namespaces: %s", err))
return 2
}
_, ok := extractListData(secret)
if Format(c.UI) != "table" {
if secret == nil || secret.Data != nil || !ok {
OutputData(c.UI, map[string]interface{}{})
return 2
}
}
if secret == nil {
c.UI.Error(fmt.Sprintf("No namespaces found"))
return 2
@ -85,7 +94,7 @@ func (c *NamespaceListCommand) Run(args []string) int {
return OutputSecret(c.UI, secret)
}
if _, ok := extractListData(secret); !ok {
if !ok {
c.UI.Error(fmt.Sprintf("No entries found"))
return 2
}