Skip to content

Commit

Permalink
Revert "orga list: display ✓ for the current organization"
Browse files Browse the repository at this point in the history
This reverts commit fb6bd49.
  • Loading branch information
brmzkw committed Aug 18, 2023
1 parent 628d9c8 commit 8de0c69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
28 changes: 12 additions & 16 deletions pkg/koyeb/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const (
ctx_logs_client
ctx_mapper
ctx_renderer
ctx_organization
)

// SetupCLIContext is called by the root command to setup the context for all subcommands.
Expand All @@ -38,7 +37,6 @@ func SetupCLIContext(cmd *cobra.Command, organization string) error {
ctx = context.WithValue(ctx, ctx_logs_client, logsApiClient)
ctx = context.WithValue(ctx, ctx_mapper, idmapper.NewMapper(ctx, apiClient))
ctx = context.WithValue(ctx, ctx_renderer, renderer.NewRenderer(outputFormat))
ctx = context.WithValue(ctx, ctx_organization, organization)
cmd.SetContext(ctx)

if organization != "" {
Expand All @@ -53,25 +51,23 @@ func SetupCLIContext(cmd *cobra.Command, organization string) error {
}

type CLIContext struct {
Context context.Context
Client *koyeb.APIClient
LogsClient *LogsAPIClient
Mapper *idmapper.Mapper
Token string
Renderer renderer.Renderer
Organization string
Context context.Context
Client *koyeb.APIClient
LogsClient *LogsAPIClient
Mapper *idmapper.Mapper
Token string
Renderer renderer.Renderer
}

// GetCLIContext transforms the untyped context passed to cobra commands into a CLIContext.
func GetCLIContext(ctx context.Context) *CLIContext {
return &CLIContext{
Context: ctx,
Client: ctx.Value(ctx_client).(*koyeb.APIClient),
LogsClient: ctx.Value(ctx_logs_client).(*LogsAPIClient),
Mapper: ctx.Value(ctx_mapper).(*idmapper.Mapper),
Token: ctx.Value(koyeb.ContextAccessToken).(string),
Renderer: ctx.Value(ctx_renderer).(renderer.Renderer),
Organization: ctx.Value(ctx_organization).(string),
Context: ctx,
Client: ctx.Value(ctx_client).(*koyeb.APIClient),
LogsClient: ctx.Value(ctx_logs_client).(*LogsAPIClient),
Mapper: ctx.Value(ctx_mapper).(*idmapper.Mapper),
Token: ctx.Value(koyeb.ContextAccessToken).(string),
Renderer: ctx.Value(ctx_renderer).(renderer.Renderer),
}
}

Expand Down
31 changes: 12 additions & 19 deletions pkg/koyeb/organizations_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,22 @@ func (h *OrganizationHandler) List(ctx *CLIContext, cmd *cobra.Command, args []s
}

full := GetBoolFlags(cmd, "full")
reply := NewListOragnizationsReply(ctx.Mapper, &koyeb.ListOrganizationMembersReply{Members: list}, full, ctx.Organization)
reply := NewListOragnizationsReply(ctx.Mapper, &koyeb.ListOrganizationMembersReply{Members: list}, full)
ctx.Renderer.Render(reply)
return nil
}

type ListOrganizationsReply struct {
mapper *idmapper.Mapper
value *koyeb.ListOrganizationMembersReply
full bool
currentOrganization string
mapper *idmapper.Mapper
value *koyeb.ListOrganizationMembersReply
full bool
}

func NewListOragnizationsReply(mapper *idmapper.Mapper, value *koyeb.ListOrganizationMembersReply, full bool, currentOrganization string) *ListOrganizationsReply {
func NewListOragnizationsReply(mapper *idmapper.Mapper, value *koyeb.ListOrganizationMembersReply, full bool) *ListOrganizationsReply {
return &ListOrganizationsReply{
mapper: mapper,
value: value,
full: full,
currentOrganization: currentOrganization,
mapper: mapper,
value: value,
full: full,
}
}

Expand All @@ -78,23 +76,18 @@ func (r *ListOrganizationsReply) MarshalBinary() ([]byte, error) {
}

func (r *ListOrganizationsReply) Headers() []string {
return []string{"id", "name", "plan", "current"}
return []string{"id", "name", "plan"}
}

func (r *ListOrganizationsReply) Fields() []map[string]string {
items := r.value.GetMembers()
resp := make([]map[string]string, 0, len(items))

for _, member := range items {
current := ""
if member.Organization.GetId() == r.currentOrganization {
current = "✓"
}
fields := map[string]string{
"id": renderer.FormatID(member.Organization.GetId(), r.full),
"name": member.Organization.GetName(),
"plan": string(member.Organization.GetPlan()),
"current": current,
"id": renderer.FormatID(member.Organization.GetId(), r.full),
"name": member.Organization.GetName(),
"plan": string(member.Organization.GetPlan()),
}
resp = append(resp, fields)
}
Expand Down

0 comments on commit 8de0c69

Please sign in to comment.