Skip to content

feat(server): add rename command for dedicated servers#218

Closed
canyugs wants to merge 3 commits intomainfrom
feat/server-rename
Closed

feat(server): add rename command for dedicated servers#218
canyugs wants to merge 3 commits intomainfrom
feat/server-rename

Conversation

@canyugs
Copy link
Copy Markdown
Contributor

@canyugs canyugs commented Apr 9, 2026

Summary

  • The Zeabur dashboard supports renaming dedicated servers, but the CLI had no equivalent. This wires up the existing updateServerName GraphQL mutation through a new zeabur server rename subcommand.
  • Supports both interactive (server picker + name prompt) and non-interactive (--id / --name flags or positional arg) modes, matching the convention of server reboot.

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./... passes (no regressions)
  • zeabur server rename --help shows expected flags
  • Non-interactive error paths verified: missing --id, missing --name, conflicting positional/--id
  • Manual end-to-end against a real dedicated server

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a new server "rename" command. Users can rename a server via positional ID or --id plus --name, or run interactively to pick a server from a list and enter a new name.
    • Command validates mismatched IDs, prompts for missing inputs in interactive mode, and reports success or clear errors when required inputs are missing or the operation fails.

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>
Copilot AI review requested due to automatic review settings April 9, 2026 08:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ad9ba49-e6d4-4ab7-b1f1-e502edd676b1

📥 Commits

Reviewing files that changed from the base of the PR and between fb69ded and c985cd2.

📒 Files selected for processing (1)
  • internal/cmd/server/rename/rename.go
✅ Files skipped from review due to trivial changes (1)
  • internal/cmd/server/rename/rename.go

Walkthrough

Adds a new rename server command (interactive and non-interactive), registers it under the server CLI, and extends the API with RenameServer plus a client implementation that performs a GraphQL updateServerName mutation.

Changes

Cohort / File(s) Summary
Rename Command Implementation
internal/cmd/server/rename/rename.go
Adds NewCmdRename CLI command: supports positional server-id and --id/--name flags, validates conflicts, implements interactive flow (lists servers via API, prompts select/input) and non-interactive flow, calls ApiClient.RenameServer.
Command Registration
internal/cmd/server/server.go
Imports and registers the new rename subcommand into the server command hierarchy.
API Interface & Client
pkg/api/interface.go, pkg/api/server.go
Adds RenameServer(ctx, id, name string) error to ServerAPI and implements client.RenameServer that sends a GraphQL updateServerName mutation and returns errors on failure or non-acceptance.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main change: adding a new rename command for dedicated servers. It is concise, specific, and directly reflects the primary feature being added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/server-rename

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RenameServer to the API client (mutation call + boolean acceptance check).
  • Extend the public api.ServerAPI interface with RenameServer.
  • Register a new server rename Cobra 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/cmd/server/rename/rename.go (1)

57-66: Prefer reusing model.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

📥 Commits

Reviewing files that changed from the base of the PR and between 4750f37 and fb69ded.

📒 Files selected for processing (4)
  • internal/cmd/server/rename/rename.go
  • internal/cmd/server/server.go
  • pkg/api/interface.go
  • pkg/api/server.go

Comment thread internal/cmd/server/rename/rename.go Outdated
canyugs and others added 2 commits April 10, 2026 01:04
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>
@canyugs
Copy link
Copy Markdown
Contributor Author

canyugs commented Apr 9, 2026

Addressed review feedback:

Applied (c985cd2): Clarified missing-id error to server-id or --id is required — both input forms are now mentioned.

Also applied (25d531c): Added strings.TrimSpace on --name so whitespace-only names are rejected client-side instead of round-tripping and producing the generic rename server was not accepted error.

Not applied — CodeRabbit nitpick about s.String(): The suggestion doesn't compile. ListServers returns model.ServerListItems, not model.Server, and ServerListItem has no String() method. Adding one to dedupe with reboot.go's formatting is worth doing but is out of scope for this PR.

@canyugs canyugs closed this Apr 9, 2026
@canyugs canyugs deleted the feat/server-rename branch April 9, 2026 17:01
canyugs added a commit that referenced this pull request Apr 13, 2026
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>
canyugs added a commit that referenced this pull request Apr 13, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants