feat(server): add rename command for dedicated servers#218
feat(server): add rename command for dedicated servers#218
Conversation
The Zeabur dashboard supports renaming dedicated servers, but the CLI had no equivalent. Wire up the existing `updateServerName` GraphQL mutation through a new `zeabur server rename` subcommand with both interactive and non-interactive modes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughAdds a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant Prompter
participant ApiClient
participant API
User->>CLI: run "server rename [server-id]" (or flags)
CLI->>CLI: validate args/flags
alt Interactive mode (f.Interactive)
CLI->>ApiClient: ListServers(ctx)
ApiClient->>API: query servers
API-->>ApiClient: servers list
ApiClient-->>CLI: servers
CLI->>Prompter: Select server / Input name
Prompter-->>CLI: selected id, name
CLI->>ApiClient: RenameServer(ctx, id, name)
ApiClient->>API: GraphQL mutation updateServerName(_id, name)
API-->>ApiClient: mutation result (accepted=true/false)
ApiClient-->>CLI: success or error
else Non-interactive
CLI->>ApiClient: RenameServer(ctx, id, name)
ApiClient->>API: GraphQL mutation updateServerName(_id, name)
API-->>ApiClient: mutation result
ApiClient-->>CLI: success or error
end
CLI-->>User: print result or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Adds a zeabur server rename command to the CLI by wiring the existing GraphQL updateServerName mutation through the API client and exposing it as a new server subcommand, following the interaction patterns used by existing server commands (e.g., server reboot).
Changes:
- Add
RenameServerto the API client (mutation call + boolean acceptance check). - Extend the public
api.ServerAPIinterface withRenameServer. - Register a new
server renameCobra subcommand supporting interactive and flag-driven modes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/api/server.go | Adds RenameServer mutation wrapper for updating a server’s name. |
| pkg/api/interface.go | Exposes RenameServer on the ServerAPI interface. |
| internal/cmd/server/server.go | Registers the new rename subcommand under server. |
| internal/cmd/server/rename/rename.go | Implements zeabur server rename (interactive picker + prompt, and non-interactive flags). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/cmd/server/rename/rename.go (1)
57-66: Prefer reusingmodel.Server.String()to avoid duplicated formatting logic.This block duplicates server-label formatting already available on the model, and similar duplication exists in reboot command formatting.
♻️ Proposed refactor
options := make([]string, len(servers)) for i, s := range servers { - location := s.IP - if s.City != nil && s.Country != nil { - location = fmt.Sprintf("%s, %s", *s.City, *s.Country) - } else if s.Country != nil { - location = *s.Country - } - options[i] = fmt.Sprintf("%s (%s)", s.Name, location) + options[i] = s.String() }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/cmd/server/rename/rename.go` around lines 57 - 66, The server label construction duplicates existing formatting; replace the manual formatting in the loop that builds options (the loop over servers producing options[i] = fmt.Sprintf("%s (%s)", s.Name, location)) with the model.Server.String() method (call s.String()) so the UI reuses the canonical representation; also update the reboot command's similar formatting to use Server.String() to avoid duplicated logic and ensure consistent labels across rename and reboot code paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/cmd/server/rename/rename.go`:
- Around line 87-88: Update the error returned when opts.id is empty to mention
both the flag and positional form: change the fmt.Errorf("--id is required")
call (the check on opts.id) to a clearer message such as fmt.Errorf("server id
is required (use --id or provide positional 'server-id')") so callers know they
can pass either the --id flag or the positional server-id argument.
---
Nitpick comments:
In `@internal/cmd/server/rename/rename.go`:
- Around line 57-66: The server label construction duplicates existing
formatting; replace the manual formatting in the loop that builds options (the
loop over servers producing options[i] = fmt.Sprintf("%s (%s)", s.Name,
location)) with the model.Server.String() method (call s.String()) so the UI
reuses the canonical representation; also update the reboot command's similar
formatting to use Server.String() to avoid duplicated logic and ensure
consistent labels across rename and reboot code paths.
🪄 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: 59853e77-3a22-42cd-af62-ef8cb3caa6aa
📒 Files selected for processing (4)
internal/cmd/server/rename/rename.gointernal/cmd/server/server.gopkg/api/interface.gopkg/api/server.go
Client-side trim prevents passing " " as --name, which would otherwise round-trip to the backend and surface a generic "rename server was not accepted" error. Addresses review feedback from PR #218. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mention both the positional server-id arg and the --id flag so users know either form is accepted. Addresses CodeRabbit review on PR #218. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Addressed review feedback: Applied (c985cd2): Clarified missing-id error to Also applied (25d531c): Added Not applied — CodeRabbit nitpick about |
Client-side trim prevents passing " " as --name, which would otherwise round-trip to the backend and surface a generic "rename server was not accepted" error. Addresses review feedback from PR #218. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mention both the positional server-id arg and the --id flag so users know either form is accepted. Addresses CodeRabbit review on PR #218. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
updateServerNameGraphQL mutation through a newzeabur server renamesubcommand.--id/--nameflags or positional arg) modes, matching the convention ofserver reboot.Test plan
go build ./...passesgo vet ./...passesgo test ./...passes (no regressions)zeabur server rename --helpshows expected flags--id, missing--name, conflicting positional/--id🤖 Generated with Claude Code
Summary by CodeRabbit