Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ coverage.out

# Claude Code
.claude/worktrees/
.claude/settings.local.json
5 changes: 4 additions & 1 deletion cmd/alias/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
22 changes: 3 additions & 19 deletions cmd/domain/edit.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package domain

import (
"encoding/json"
"fmt"
"strconv"

Expand Down Expand Up @@ -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
}
22 changes: 22 additions & 0 deletions internal/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading