(opts *ViewOptions, cmd *cobra.Command)
| 84 | } |
| 85 | |
| 86 | func viewRun(opts *ViewOptions, cmd *cobra.Command) error { |
| 87 | tenant, err := opts.Client.Tenants.GetByIdentifier(opts.idOrName) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | environmentMap, err := shared.GetEnvironmentMapForTenants(opts.Client, []*tenants.Tenant{tenant}) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | |
| 97 | projectMap, err := shared.GetProjectMap(opts.Client, []*tenants.Tenant{tenant}) |
| 98 | if err != nil { |
| 99 | return err |
| 100 | } |
| 101 | |
| 102 | return output.PrintResource(tenant, cmd, output.Mappers[*tenants.Tenant]{ |
| 103 | Json: func(t *tenants.Tenant) any { |
| 104 | |
| 105 | projectEnvironments := []shared.ProjectEnvironment{} |
| 106 | |
| 107 | for p := range t.ProjectEnvironments { |
| 108 | projectEntity := output.IdAndName{Id: p, Name: projectMap[p]} |
| 109 | environments, err := shared.ResolveEntities(t.ProjectEnvironments[p], environmentMap) |
| 110 | if err != nil { |
| 111 | return err |
| 112 | } |
| 113 | projectEnvironments = append(projectEnvironments, shared.ProjectEnvironment{Project: projectEntity, Environments: environments}) |
| 114 | } |
| 115 | |
| 116 | t.Links = nil // ensure the links collection is not serialised |
| 117 | return shared.TenantAsJson{ |
| 118 | Tenant: t, |
| 119 | ProjectEnvironments: projectEnvironments, |
| 120 | } |
| 121 | }, |
| 122 | Table: output.TableDefinition[*tenants.Tenant]{ |
| 123 | Header: []string{"NAME", "DESCRIPTION", "ID", "IS DISABLED", "TAGS"}, |
| 124 | Row: func(t *tenants.Tenant) []string { |
| 125 | return []string{output.Bold(t.Name), t.Description, output.Dim(t.GetID()), strconv.FormatBool(t.IsDisabled), output.FormatAsList(t.TenantTags)} |
| 126 | }, |
| 127 | }, |
| 128 | Basic: func(item *tenants.Tenant) string { |
| 129 | var s strings.Builder |
| 130 | |
| 131 | s.WriteString(fmt.Sprintf("%s %s\n", output.Bold(tenant.Name), output.Dimf("(%s)", tenant.ID))) |
| 132 | |
| 133 | if len(tenant.TenantTags) > 0 { |
| 134 | s.WriteString(fmt.Sprintf("Tags: %s\n", output.FormatAsList(tenant.TenantTags))) |
| 135 | } |
| 136 | |
| 137 | if tenant.Description == "" { |
| 138 | s.WriteString(fmt.Sprintln(output.Dim(constants.NoDescription))) |
| 139 | } else { |
| 140 | s.WriteString(fmt.Sprintln(output.Dim(tenant.Description))) |
| 141 | } |
| 142 | |
| 143 | if tenant.IsDisabled { |
no test coverage detected