Skip to content

Commit

Permalink
gitpod ws list --field
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Oct 31, 2023
1 parent cb60474 commit 667b6c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/local-app/cmd/organization-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ var listOrganizationCommand = &cobra.Command{

func init() {
orgCmd.AddCommand(listOrganizationCommand)
listOrganizationCommand.Flags().StringVarP(&orgListOutputField, "field", "f", "", "output a specific field of the organization")
listOrganizationCommand.Flags().StringVarP(&orgListOutputField, "field", "f", "", "output a specific field of the organizations")
}
34 changes: 32 additions & 2 deletions components/local-app/cmd/workspace-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log/slog"
"os"
"reflect"
"time"

"strings"
Expand Down Expand Up @@ -50,6 +51,15 @@ func getWorkspaceBranch(ws *v1.Workspace) string {
return value
}

type WorkspaceDisplayData struct {
Repository string
Branch string
Id string
Status string
}

var wsListOutputField string

// listWorkspaceCommand lists all available workspaces
var listWorkspaceCommand = &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -79,15 +89,35 @@ var listWorkspaceCommand = &cobra.Command{
repository := getWorkspaceRepo(workspace)
branch := getWorkspaceBranch(workspace)

table.Append([]string{repository, branch, workspace.WorkspaceId, TranslatePhase(workspace.GetStatus().Instance.Status.Phase.String())})
wsData := WorkspaceDisplayData{
Repository: repository,
Branch: branch,
Id: workspace.WorkspaceId,
Status: TranslatePhase(workspace.GetStatus().Instance.Status.Phase.String()),
}

if wsListOutputField != "" {
wsListOutputField = common.CapitalizeFirst(wsListOutputField)
val := reflect.ValueOf(wsData)
if fieldVal := val.FieldByName(wsListOutputField); fieldVal.IsValid() {
fmt.Printf("%v\n", fieldVal.Interface())
} else {
return fmt.Errorf("Field '%s' is an invalid field for workspaces", wsListOutputField)
}
} else {
table.Append([]string{wsData.Repository, wsData.Branch, wsData.Id, wsData.Status})
}
}

table.Render()
if wsListOutputField == "" {
table.Render()
}

return nil
},
}

func init() {
wsCmd.AddCommand(listWorkspaceCommand)
listWorkspaceCommand.Flags().StringVarP(&wsListOutputField, "field", "f", "", "output a specific field of the workspaces")
}

0 comments on commit 667b6c4

Please sign in to comment.