diff --git a/.gitignore b/.gitignore index d421351..ac5aa5e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ coverage.out # Claude Code .claude/worktrees/ +.claude/settings.local.json diff --git a/cmd/alias/create.go b/cmd/alias/create.go index f5a6391..f412aa3 100644 --- a/cmd/alias/create.go +++ b/cmd/alias/create.go @@ -91,6 +91,9 @@ func runCreate(cmd *cobra.Command, args []string) error { if createMode != "" && createMode != "uuid" && createMode != "word" { return fmt.Errorf("--mode must be 'uuid' or 'word'") } + if createMode != "" && !createRandom { + return fmt.Errorf("--mode can only be used with --random") + } if createRandom { alias, rawJSON, err := client.CreateRandomAlias(createNote, createHostname, createMode) @@ -116,7 +119,7 @@ func runCreate(cmd *cobra.Command, args []string) error { } // Get available options - opts, _, err := client.GetAliasOptions("") + opts, _, err := client.GetAliasOptions(createHostname) if err != nil { return err } diff --git a/cmd/domain/edit.go b/cmd/domain/edit.go index 4891790..d96f0fa 100644 --- a/cmd/domain/edit.go +++ b/cmd/domain/edit.go @@ -1,7 +1,6 @@ package domain import ( - "encoding/json" "fmt" "strconv" @@ -121,30 +120,15 @@ func runEdit(cmd *cobra.Command, args []string) error { output.PrintSuccess("Domain updated") if editJQ != "" || editJSON { - domains, _, err := client.ListCustomDomains() + _, rawJSON, err := client.GetCustomDomain(id) if err != nil { output.PrintWarning("Updated, but failed to fetch updated state: %v", err) return nil } - var found *api.CustomDomain - for i := range domains { - if domains[i].ID == id { - found = &domains[i] - break - } - } - if found == nil { - output.PrintWarning("Updated, but domain ID %d not found in list", id) - return nil - } - data, err := json.Marshal(found) - if err != nil { - return fmt.Errorf("failed to marshal domain: %w", err) - } if editJQ != "" { - return output.PrintJQ(data, editJQ) + return output.PrintJQ(rawJSON, editJQ) } - return output.PrintJSON(data) + return output.PrintJSON(rawJSON) } return nil } diff --git a/internal/api/client_test.go b/internal/api/client_test.go index 545573d..1e1c225 100644 --- a/internal/api/client_test.go +++ b/internal/api/client_test.go @@ -351,6 +351,28 @@ func TestClient_CreateRandomAlias(t *testing.T) { } } +func TestClient_CreateRandomAlias_WithHostname(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + hostname := r.URL.Query().Get("hostname") + if hostname != "github.com" { + t.Errorf("expected hostname=github.com, got %q", hostname) + } + w.WriteHeader(201) + alias := Alias{ID: 102, Email: "gh-random@sl.local"} + _ = json.NewEncoder(w).Encode(alias) + })) + defer srv.Close() + + c := newTestClient(t, srv) + alias, _, err := c.CreateRandomAlias("", "github.com", "") + if err != nil { + t.Fatalf("CreateRandomAlias with hostname: %v", err) + } + if alias.ID != 102 { + t.Errorf("expected ID 102, got %d", alias.ID) + } +} + func TestClient_CreateRandomAlias_WithMode(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" {