Skip to content

Commit 653e6b6

Browse files
committed
Polish API key command output
1 parent 6c9deba commit 653e6b6

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

cmd/api_keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (c APIKeysCmd) Create(ctx context.Context, in APIKeysCreateInput) error {
8181
return util.PrintPrettyJSON(key)
8282
}
8383

84+
pterm.Success.Printf("Created API key: %s\n", key.ID)
8485
renderCreatedAPIKey(key)
8586
return nil
8687
}
@@ -175,7 +176,6 @@ func (c APIKeysCmd) Update(ctx context.Context, in APIKeysUpdateInput) error {
175176
}
176177

177178
pterm.Success.Printf("Updated API key: %s\n", key.ID)
178-
renderAPIKeyDetails(key)
179179
return nil
180180
}
181181

cmd/api_keys_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func TestAPIKeysCreateBuildsParamsAndPrintsPlaintextKey(t *testing.T) {
9797
require.NoError(t, err)
9898

9999
out := buf.String()
100+
assert.Contains(t, out, "Created API key: key_123")
100101
assert.Contains(t, out, "key_123")
101102
assert.Contains(t, out, "sk_live_123")
102103
assert.Contains(t, out, "Prod")
@@ -201,6 +202,26 @@ func TestAPIKeysUpdateRequiresName(t *testing.T) {
201202
assert.Contains(t, err.Error(), "--name is required")
202203
}
203204

205+
func TestAPIKeysUpdatePrintsTerseSuccess(t *testing.T) {
206+
buf := capturePtermOutput(t)
207+
fake := &FakeAPIKeysService{
208+
UpdateFunc: func(ctx context.Context, id string, body kernel.APIKeyUpdateParams, opts ...option.RequestOption) (*kernel.APIKey, error) {
209+
assert.Equal(t, "key_123", id)
210+
assert.Equal(t, "renamed", body.Name)
211+
return apiKeyFromJSON(`{"id":"key_123","name":"renamed","masked_key":"sk_...123","created_at":"2026-05-27T12:00:00Z","created_by":{"id":"user_123","email":"dev@example.com","name":"Dev"},"expires_at":null,"project_id":null,"project_name":null}`), nil
212+
},
213+
}
214+
c := APIKeysCmd{apiKeys: fake}
215+
216+
err := c.Update(context.Background(), APIKeysUpdateInput{ID: "key_123", Name: "renamed"})
217+
require.NoError(t, err)
218+
219+
out := buf.String()
220+
assert.Contains(t, out, "Updated API key: key_123")
221+
assert.NotContains(t, out, "Masked Key")
222+
assert.NotContains(t, out, "sk_...123")
223+
}
224+
204225
func TestAPIKeysDeleteSkipsConfirmation(t *testing.T) {
205226
buf := capturePtermOutput(t)
206227
deleted := false

0 commit comments

Comments
 (0)