Add Output Fields support (#1192)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-05-04 20:57:35 -04:00
1 parent 1948984ca2
commit 22d5c88a0b
84 files changed
+5688 -2122

No files matched your search

+39 -23
View File
@@ -149,39 +149,43 @@ func (c *Command) printListTable(items []*groups.Group) string {
"",
"Group information:",
}
for i, g := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", g.Id),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if c.FlagRecursive {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", g.Scope.Id),
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if true {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", g.Version),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if g.Name != "" {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", g.Name),
fmt.Sprintf(" Name: %s", item.Name),
)
}
if g.Description != "" {
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", g.Description),
fmt.Sprintf(" Description: %s", item.Description),
)
}
if len(g.AuthorizedActions) > 0 {
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, g.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -189,14 +193,21 @@ func (c *Command) printListTable(items []*groups.Group) string {
return base.WrapForHelpText(output)
}
func printItemTable(item *groups.Group) string {
nonAttributeMap := map[string]interface{}{
"ID": item.Id,
"Version": item.Version,
"Created Time": item.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": item.UpdatedTime.Local().Format(time.RFC1123),
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*groups.Group)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
@@ -224,9 +235,14 @@ func printItemTable(item *groups.Group) string {
"",
"Group information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
}
if item.Scope != nil {
ret = append(ret,
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
@@ -316,8 +316,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*groups.Group)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {