Update CLI output functions to show scope info and cleanup (#416)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-23 03:01:39 -04:00
1 parent 38ce9d9eac
commit 03436a73de
15 files changed
+222 -295

No files matched your search

+14 -32
View File
@@ -1,7 +1,6 @@
package hostsets
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/hostsets"
@@ -9,15 +8,12 @@ import (
)
func generateHostSetTableOutput(in *hostsets.HostSet) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Host Catalog ID": in.HostCatalogId,
}
@@ -28,35 +24,20 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
ret = append(ret, "", "Host set information:")
ret = append(ret,
// We do +2 because there is another +2 offset for attributes below
ret := []string{
"",
"Host Set information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.HostIds) > 0 {
ret = append(ret,
"",
" Host IDs:",
base.WrapSlice(4, in.HostIds),
)
@@ -64,7 +45,8 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
if len(in.Attributes) > 0 {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -72,4 +54,4 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{}
var keySubstMap = map[string]string{}