Skip to content

Commit 5e30d8e

Browse files
fix(application): persist configuration when create uses structured output (#264)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 375eed4 commit 5e30d8e

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

pkg/cmd/application/create/create.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,13 @@ func createApplication(
287287
" Add a payment method if needed, then retry with: algolia application upgrade --plan %s\n",
288288
target.ID,
289289
)
290-
if !opts.structuredOutput() {
291-
_ = apputil.ConfigureProfile(
292-
opts.IO,
293-
opts.Config,
294-
appDetails,
295-
opts.ProfileName,
296-
opts.Default,
297-
)
298-
}
290+
_ = apputil.ConfigureProfile(
291+
opts.IO,
292+
opts.Config,
293+
appDetails,
294+
opts.ProfileName,
295+
opts.Default,
296+
)
299297
return result, fmt.Errorf(
300298
"failed to apply the %q plan to application %s: %w",
301299
target.Name,
@@ -312,22 +310,25 @@ func createApplication(
312310
)
313311
}
314312

313+
tracker.SetStep(telemetry.StepProfileConfigure)
314+
if err := apputil.ConfigureProfile(
315+
opts.IO,
316+
opts.Config,
317+
appDetails,
318+
opts.ProfileName,
319+
opts.Default,
320+
); err != nil {
321+
return result, err
322+
}
323+
315324
if opts.structuredOutput() {
316325
p, err := opts.PrintFlags.ToPrinter()
317326
if err != nil {
318327
return result, err
319328
}
320329
return result, p.Print(opts.IO, appDetails)
321330
}
322-
323-
tracker.SetStep(telemetry.StepProfileConfigure)
324-
return result, apputil.ConfigureProfile(
325-
opts.IO,
326-
opts.Config,
327-
appDetails,
328-
opts.ProfileName,
329-
opts.Default,
330-
)
331+
return result, nil
331332
}
332333

333334
func (opts *CreateOptions) structuredOutput() bool {

pkg/cmd/application/create/create_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func newOpts(
242242
t.Helper()
243243
seedToken(t)
244244

245-
f, out := test.NewFactory(isTTY, nil, nil, "")
245+
f, out := test.NewFactory(isTTY, nil, test.NewDefaultConfigStub(), "")
246246
opened := new(string)
247247
opts := &CreateOptions{
248248
IO: f.IOStreams,
@@ -278,6 +278,21 @@ func TestRun_FreeNonInteractive(t *testing.T) {
278278
assert.Contains(t, out.String(), "APP1")
279279
}
280280

281+
func TestRun_StructuredOutputPersistsProfile(t *testing.T) {
282+
srv := newServer(t, `{"has_payment_method": false}`)
283+
defer srv.Close()
284+
285+
opts, out, _ := newOpts(t, srv, false)
286+
cfg := opts.Config.(*test.ConfigStub)
287+
opts.AcceptTerms = true
288+
opts.Default = true
289+
290+
require.NoError(t, runCreateCmd(context.Background(), opts))
291+
assert.Equal(t, "APP1", cfg.CurrentAppID)
292+
assert.Equal(t, "test-api-key", cfg.SavedApps["APP1"].APIKey)
293+
assert.Contains(t, out.String(), "APP1")
294+
}
295+
281296
func TestRun_NonInteractiveRequiresAcceptTerms(t *testing.T) {
282297
srv := newServer(t, `{"has_payment_method": true}`)
283298
defer srv.Close()

0 commit comments

Comments
 (0)