From 72cb4834064a75a9d9e54438300941875e7d972b Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 4 Jun 2019 13:36:34 -0400 Subject: [PATCH] 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 --- command/audit_list.go | 10 +++++----- command/kv_list.go | 11 ++++++++++- command/list.go | 11 ++++++++++- command/namespace_list.go | 11 ++++++++++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/command/audit_list.go b/command/audit_list.go index be3c87807579..392d55bae222 100644 --- a/command/audit_list.go +++ b/command/audit_list.go @@ -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 diff --git a/command/kv_list.go b/command/kv_list.go index faedd6f3f429..0066c1f13215 100644 --- a/command/kv_list.go +++ b/command/kv_list.go @@ -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 } diff --git a/command/list.go b/command/list.go index 56762151ac24..e29b842a9cf1 100644 --- a/command/list.go +++ b/command/list.go @@ -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 } diff --git a/command/namespace_list.go b/command/namespace_list.go index 893e1a76e4cd..f06579b0d898 100644 --- a/command/namespace_list.go +++ b/command/namespace_list.go @@ -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 }