Skip to content

Commit

Permalink
--field for gitpod organizations list
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Oct 31, 2023
1 parent e25f68d commit cb60474
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
22 changes: 21 additions & 1 deletion components/local-app/cmd/organization-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package cmd

import (
"context"
"fmt"
"reflect"
"time"

"github.com/bufbuild/connect-go"
Expand All @@ -14,6 +16,8 @@ import (
"github.com/spf13/cobra"
)

var orgListOutputField string

// listOrganizationCommand lists all available organizations
var listOrganizationCommand = &cobra.Command{
Use: "list",
Expand All @@ -32,12 +36,28 @@ var listOrganizationCommand = &cobra.Command{
return err
}

outputOrgs(orgs.Msg.GetTeams())
orgData := orgs.Msg.GetTeams()

if orgListOutputField != "" {
orgListOutputField = common.CapitalizeFirst(orgListOutputField)
for _, org := range orgData {
val := reflect.ValueOf(org).Elem()
if fieldVal := val.FieldByName(orgListOutputField); fieldVal.IsValid() {
fmt.Printf("%v\n", fieldVal.Interface())
} else {
return fmt.Errorf("Field '%s' is an invalid field for organizations", orgListOutputField)
}
}
return nil
}

outputOrgs(orgData)

return nil
},
}

func init() {
orgCmd.AddCommand(listOrganizationCommand)
listOrganizationCommand.Flags().StringVarP(&orgListOutputField, "field", "f", "", "output a specific field of the organization")
}
16 changes: 16 additions & 0 deletions components/local-app/pkg/common/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.

package common

import "unicode"

func CapitalizeFirst(s string) string {
if s == "" {
return ""
}
r := []rune(s)
r[0] = unicode.ToUpper(r[0])
return string(r)
}

0 comments on commit cb60474

Please sign in to comment.