-
Notifications
You must be signed in to change notification settings - Fork 16
feat: support team workspace via zeabur workspace (PLA-1590)
#244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c593186
feat: support team workspace via `zeabur workspace` (PLA-1590)
BruceDu521 c515cee
fix: address PLA-1590 review (workspace caching, deploy hint, etc.)
BruceDu521 61e8378
fix: make `--name` lookups workspace-aware (PLA-1590 review F2)
BruceDu521 b97244f
fix: lint, set.go name backfill, Factory regression tests (PLA-1590)
BruceDu521 736851b
fix: workspace current / list must honor --workspace override (PLA-1590)
BruceDu521 b5667e2
fix: --workspace must not read or write persisted inner context (PLA-…
BruceDu521 7a1be0e
fix: route interactive + implicit-context consumers through ephemeral…
BruceDu521 da5da8f
test: cover lazy-resolution in DefaultIDNameByContext (PLA-1590)
BruceDu521 e24000d
fix: gate `context set project --id` against cross-workspace ID in te…
BruceDu521 02c32e4
fix: address CodeRabbit lint + workspace-list / ephemeral-cache nits …
BruceDu521 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Package clear implements `zeabur workspace clear`. Clear is the ONLY way | ||
| // to return to the personal workspace — `workspace switch personal` is | ||
| // intentionally interpreted as "find a team literally named personal" because | ||
| // team names are unconstrained. | ||
| package clear | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/zeabur/cli/internal/cmdutil" | ||
| ) | ||
|
|
||
| // NewCmdClear builds `zeabur workspace clear`. | ||
| func NewCmdClear(f *cmdutil.Factory) *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "clear", | ||
| Short: "Switch back to the personal workspace", | ||
| Long: `Return to the personal workspace. | ||
|
|
||
| This is the only way to switch to personal: `+"`workspace switch personal`"+` | ||
| always looks for a team literally named "personal". This also clears the | ||
| persisted project, environment, and service context because resource IDs do | ||
| not overlap between workspaces.`, | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return run(f) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func run(f *cmdutil.Factory) error { | ||
| cctx := f.Config.GetContext() | ||
| prev := cctx.GetWorkspace() | ||
| prevProject := cctx.GetProject() | ||
|
|
||
| cctx.ClearWorkspace() | ||
| cctx.ClearAll() | ||
|
|
||
| if prev.IsPersonal() { | ||
| fmt.Println("Already on personal workspace.") | ||
| } else { | ||
| fmt.Printf("Switched to personal workspace (was: %s).\n", prev.Name) | ||
| } | ||
| if !prevProject.Empty() { | ||
| fmt.Printf("Project context cleared (was: %s).\n", prevProject.GetName()) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Package current implements `zeabur workspace current`. | ||
| package current | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/zeabur/cli/internal/cmdutil" | ||
| ) | ||
|
|
||
| // NewCmdCurrent builds `zeabur workspace current`. | ||
| func NewCmdCurrent(f *cmdutil.Factory) *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "current", | ||
| Short: "Show the workspace the CLI is currently acting under", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return run(f) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func run(f *cmdutil.Factory) error { | ||
| ws := f.Config.GetContext().GetWorkspace() | ||
| if ws.IsPersonal() { | ||
| label := f.Config.GetUser() | ||
| if label == "" { | ||
| label = f.Config.GetUsername() | ||
| } | ||
| if label == "" { | ||
| label = "(you)" | ||
| } | ||
| fmt.Printf("personal (%s)\n", label) | ||
| return nil | ||
| } | ||
|
|
||
| // For a team workspace also fetch the freshest role from the backend so | ||
| // `current` reports the live role rather than whatever was cached when | ||
| // the workspace was last switched in. | ||
| role := "" | ||
| teams, err := f.ApiClient.ListTeams(context.Background()) | ||
| if err == nil { | ||
| for _, t := range teams { | ||
| if t.ID == ws.ID && t.MyRole != nil { | ||
| role = " " + t.MyRole.Display() | ||
| break | ||
| } | ||
| } | ||
| } | ||
| fmt.Printf("%s [%s] team%s\n", ws.Name, ws.ID, role) | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Package list implements `zeabur workspace list`. | ||
| package list | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "text/tabwriter" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/zeabur/cli/internal/cmdutil" | ||
| ) | ||
|
|
||
| // NewCmdList builds `zeabur workspace list`. | ||
| func NewCmdList(f *cmdutil.Factory) *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List the personal workspace and every team the caller belongs to", | ||
| Aliases: []string{"ls"}, | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return run(f) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func run(f *cmdutil.Factory) error { | ||
| teams, err := f.ApiClient.ListTeams(context.Background()) | ||
| if err != nil { | ||
| return fmt.Errorf("list teams: %w", err) | ||
| } | ||
|
|
||
| currentID := f.Config.GetContext().GetWorkspace().ID | ||
|
|
||
| w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) | ||
|
|
||
| // Personal always renders first. The 24-space placeholder keeps the | ||
| // columns aligned with the team rows that follow. | ||
| personalMarker := " " | ||
| if currentID == "" { | ||
| personalMarker = "*" | ||
| } | ||
| personalLabel := f.Config.GetUser() | ||
| if personalLabel == "" { | ||
| personalLabel = f.Config.GetUsername() | ||
| } | ||
| if personalLabel == "" { | ||
| personalLabel = "(you)" | ||
| } | ||
| fmt.Fprintf(w, "%s\tpersonal\t\t\t(%s)\n", personalMarker, personalLabel) | ||
|
|
||
| for _, t := range teams { | ||
| marker := " " | ||
| if t.ID == currentID { | ||
| marker = "*" | ||
| } | ||
| role := "" | ||
| if t.MyRole != nil { | ||
| role = t.MyRole.Display() | ||
| } | ||
| fmt.Fprintf(w, "%s\t%s\t%s\tteam\t%s\n", marker, t.ID, t.Name, role) | ||
| } | ||
|
|
||
| if err := w.Flush(); err != nil { | ||
| return fmt.Errorf("render table: %w", err) | ||
| } | ||
|
|
||
| if currentID != "" { | ||
| // If the persisted workspace is no longer in the membership list | ||
| // (e.g. the team was deleted / the caller was removed), surface it | ||
| // so the user knows the next command may behave unexpectedly. We | ||
| // don't auto-clear here — that's the lazy-verify path in root. | ||
| seen := false | ||
| for _, t := range teams { | ||
| if t.ID == currentID { | ||
| seen = true | ||
| break | ||
| } | ||
| } | ||
| if !seen { | ||
| fmt.Fprintf(os.Stderr, | ||
| "\nwarning: the persisted workspace %s is not in your memberships any more — run `zeabur workspace clear` or switch to another workspace.\n", | ||
| currentID, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.