feat(instances): support workspace access by name or ID#166
feat(instances): support workspace access by name or ID#166feloy merged 1 commit intokortex-hub:mainfrom
Conversation
Workspaces can now be accessed using either their human-readable name or unique ID in all commands (start, stop, remove, terminal). The Manager.Get() method accepts name or ID and tries ID match first (backward compatible), then falls back to name match. Commands always output the workspace ID for consistency. Closes kortex-hub#32 Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Philippe Martin <phmartin@redhat.com>
📝 WalkthroughWalkthroughThis PR enables workspaces to be accessed by either name or ID across all operational commands. The Changes
Sequence DiagramsequenceDiagram
actor User
participant Command
participant Manager
participant Instance
User->>Command: start my-project<br/>(NAME|ID argument)
activate Command
Command->>Manager: Get("my-project")
activate Manager
Manager->>Manager: scan by ID match
Manager->>Manager: scan by name match
Manager-->>Command: Instance (resolved)
deactivate Manager
Command->>Instance: GetID()
Instance-->>Command: workspace-id-123
deactivate Command
Command->>Manager: Start(ctx, workspace-id-123)
activate Manager
Manager-->>User: success, outputs workspace-id-123
deactivate Manager
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/cmd/autocomplete.go (1)
33-34: Optional: rename helper to reflect returned values.
getFilteredWorkspaceIDsnow returns IDs and names. Renaming it to something likegetFilteredWorkspaceCompletionswould reduce ambiguity.♻️ Proposed rename
-// getFilteredWorkspaceIDs retrieves workspace IDs and names, optionally filtered by state -func getFilteredWorkspaceIDs(cmd *cobra.Command, filter stateFilter) ([]string, cobra.ShellCompDirective) { +// getFilteredWorkspaceCompletions retrieves workspace completion values (IDs and names), optionally filtered by state +func getFilteredWorkspaceCompletions(cmd *cobra.Command, filter stateFilter) ([]string, cobra.ShellCompDirective) { @@ func completeNonRunningWorkspaceID(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return getFilteredWorkspaceIDs(cmd, func(state string) bool { + return getFilteredWorkspaceCompletions(cmd, func(state string) bool { return state != "running" }) } @@ func completeRunningWorkspaceID(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return getFilteredWorkspaceIDs(cmd, func(state string) bool { + return getFilteredWorkspaceCompletions(cmd, func(state string) bool { return state == "running" }) }Also applies to: 65-77
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/cmd/autocomplete.go` around lines 33 - 34, The helper getFilteredWorkspaceIDs is misleading because it returns both IDs and display names; rename the function (e.g., to getFilteredWorkspaceCompletions) and update its signature and all call sites (including uses referenced around the previous implementation) to reflect that it returns completion entries (IDs and names) along with the cobra.ShellCompDirective; ensure you update any variable names and documentation/comments (the function comment and any callers expecting only IDs) to match the new name and return semantics so callers handle both ID and label correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/instances/manager_test.go`:
- Around line 637-674: The test "ID takes precedence over name" doesn't create a
name collision because inst2 is named "workspace-two"; change inst2's Name to
the same value as inst1 (e.g., "workspace-one") so a name match exists and
retrieving by id1 via manager.Get(id1) exercises ID-vs-name precedence; update
the inst2 creation (in the test function using
newFakeInstance/newFakeInstanceParams) to use the same Name as inst1 and keep
Accessible true, then assert that manager.Get(id1) returns the instance with
GetID() == id1 and GetName() == "workspace-one".
---
Nitpick comments:
In `@pkg/cmd/autocomplete.go`:
- Around line 33-34: The helper getFilteredWorkspaceIDs is misleading because it
returns both IDs and display names; rename the function (e.g., to
getFilteredWorkspaceCompletions) and update its signature and all call sites
(including uses referenced around the previous implementation) to reflect that
it returns completion entries (IDs and names) along with the
cobra.ShellCompDirective; ensure you update any variable names and
documentation/comments (the function comment and any callers expecting only IDs)
to match the new name and return semantics so callers handle both ID and label
correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 74970e31-1f9b-42cf-b339-74063f095b2e
📒 Files selected for processing (21)
README.mdpkg/cmd/autocomplete.gopkg/cmd/autocomplete_test.gopkg/cmd/remove.gopkg/cmd/remove_test.gopkg/cmd/start.gopkg/cmd/stop.gopkg/cmd/terminal.gopkg/cmd/terminal_test.gopkg/cmd/workspace_remove.gopkg/cmd/workspace_remove_test.gopkg/cmd/workspace_start.gopkg/cmd/workspace_start_test.gopkg/cmd/workspace_stop.gopkg/cmd/workspace_stop_test.gopkg/cmd/workspace_terminal.gopkg/cmd/workspace_terminal_test.gopkg/instances/manager.gopkg/instances/manager_test.goskills/implementing-command-patterns/SKILL.mdskills/working-with-instances-manager/SKILL.md
Workspaces can now be accessed using either their human-readable name or unique ID in all commands (start, stop, remove, terminal). The Manager.Get() method accepts name or ID and tries ID match first (backward compatible), then falls back to name match. Commands always output the workspace ID for consistency.
Closes #32