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
37 changes: 19 additions & 18 deletions pkg/cmd/application/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,13 @@ func createApplication(
" Add a payment method if needed, then retry with: algolia application upgrade --plan %s\n",
target.ID,
)
if !opts.structuredOutput() {
_ = apputil.ConfigureProfile(
opts.IO,
opts.Config,
appDetails,
opts.ProfileName,
opts.Default,
)
}
_ = apputil.ConfigureProfile(
opts.IO,
opts.Config,
appDetails,
opts.ProfileName,
opts.Default,
)
return result, fmt.Errorf(
"failed to apply the %q plan to application %s: %w",
target.Name,
Expand All @@ -312,22 +310,25 @@ func createApplication(
)
}

tracker.SetStep(telemetry.StepProfileConfigure)
if err := apputil.ConfigureProfile(
opts.IO,
opts.Config,
appDetails,
opts.ProfileName,
opts.Default,
); err != nil {
return result, err
}

if opts.structuredOutput() {
p, err := opts.PrintFlags.ToPrinter()
if err != nil {
return result, err
}
return result, p.Print(opts.IO, appDetails)
}

tracker.SetStep(telemetry.StepProfileConfigure)
return result, apputil.ConfigureProfile(
opts.IO,
opts.Config,
appDetails,
opts.ProfileName,
opts.Default,
)
return result, nil
}

func (opts *CreateOptions) structuredOutput() bool {
Expand Down
17 changes: 16 additions & 1 deletion pkg/cmd/application/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func newOpts(
t.Helper()
seedToken(t)

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

func TestRun_StructuredOutputPersistsProfile(t *testing.T) {
srv := newServer(t, `{"has_payment_method": false}`)
defer srv.Close()

opts, out, _ := newOpts(t, srv, false)
cfg := opts.Config.(*test.ConfigStub)
opts.AcceptTerms = true
opts.Default = true

require.NoError(t, runCreateCmd(context.Background(), opts))
assert.Equal(t, "APP1", cfg.CurrentAppID)
assert.Equal(t, "test-api-key", cfg.SavedApps["APP1"].APIKey)
assert.Contains(t, out.String(), "APP1")
}

func TestRun_NonInteractiveRequiresAcceptTerms(t *testing.T) {
srv := newServer(t, `{"has_payment_method": true}`)
defer srv.Close()
Expand Down
Loading