Skip to content

Commit dcaa8ac

Browse files
committed
feat: clean up messages / formatting
1 parent 1bc9da1 commit dcaa8ac

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

pkg/cmd/init.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
_ "embed"
66
"fmt"
77
"io/fs"
8+
"maps"
89
"os"
910
"path/filepath"
1011
"slices"
@@ -159,16 +160,17 @@ func handleInit(ctx context.Context, cmd *cli.Command) error {
159160
err := singleFieldForm(huh.NewSelect[string]().
160161
Title("org").
161162
Description("Enter the organization for this project").
162-
Options(huh.NewOptions(orgs...)...).
163+
Options(huh.NewOptions(slices.Sorted(slices.Values(orgs))...)...).
163164
Height(len(orgs) + 2).
164165
Value(&org))
165166
if err != nil {
166167
return err
167168
}
168169
}
170+
Property("org", org)
169171

170172
var projects []stainless.Project
171-
if projectsResponse, err := cc.client.Projects.List(ctx, stainless.ProjectListParams{}); err == nil {
173+
if projectsResponse, err := cc.client.Projects.List(ctx, stainless.ProjectListParams{Org: stainless.String(org)}); err == nil {
172174
projects = projectsResponse.Data
173175
}
174176

@@ -201,6 +203,12 @@ func handleInit(ctx context.Context, cmd *cli.Command) error {
201203
}
202204
} else if len(projects) > 0 {
203205
options := make([]huh.Option[*stainless.Project], 0, len(projects)+1)
206+
projects = slices.SortedFunc(slices.Values(projects), func(p1, p2 stainless.Project) int {
207+
if p1.Slug < p2.Slug {
208+
return -1
209+
}
210+
return 1
211+
})
204212
for _, project := range projects {
205213
options = append(options, huh.NewOption(project.Slug, &project))
206214
}
@@ -225,6 +233,7 @@ func handleInit(ctx context.Context, cmd *cli.Command) error {
225233
return err
226234
}
227235
}
236+
Property("project", project)
228237

229238
return initializeWorkspace(ctx, cmd, cc, project, targets)
230239
}
@@ -234,7 +243,7 @@ func createProject(ctx context.Context, cmd *cli.Command, cc *apiCommandContext,
234243

235244
if projectName == "" {
236245
err := singleFieldForm(huh.NewInput().
237-
Title("Project Display Name").
246+
Title("project").
238247
Description("Enter a display name for your new project").
239248
Value(&projectName).
240249
DescriptionFunc(func() string {
@@ -253,7 +262,6 @@ func createProject(ctx context.Context, cmd *cli.Command, cc *apiCommandContext,
253262
return "", nil, err
254263
}
255264
}
256-
257265
info.Property("project", projectName)
258266

259267
// Determine targets
@@ -509,7 +517,7 @@ func chooseOpenAPISpecLocation() (string, error) {
509517

510518
path := suggestion
511519
err := singleFieldForm(huh.NewInput().
512-
Title("OpenAPI Specification Location").
520+
Title("OpenAPI specification location").
513521
Description("Path where the OpenAPI specification file should be stored").
514522
Value(&path).
515523
Placeholder(suggestion))
@@ -538,16 +546,16 @@ func chooseStainlessConfigLocation() (string, error) {
538546

539547
path := suggestion
540548
err := singleFieldForm(huh.NewInput().
541-
Title("Stainless Config Location").
542-
Description("Path where the Stainless configuration file should be stored").
549+
Title("Stainless config location").
550+
Description("Path where the Stainless config file should be stored").
543551
Value(&path).
544552
Placeholder(suggestion))
545553

546554
if err != nil {
547555
return "", err
548556
}
549557

550-
Property("Stainless configuration file", path)
558+
Property("Stainless config file", path)
551559
return path, nil
552560
}
553561

@@ -570,10 +578,7 @@ func downloadConfigFiles(ctx context.Context, client stainless.Client, config Wo
570578
return fmt.Errorf("config download failed: %v", err)
571579
}
572580

573-
group.Property("Available config files", "")
574-
for key := range *configRes {
575-
group.Property("- ", key)
576-
}
581+
group.Property("Available config files:", strings.Join(slices.Collect(maps.Keys(*configRes)), ", "))
577582

578583
// Helper function to write a file with confirmation if it exists
579584
writeFileWithConfirm := func(path string, content []byte, description string) error {
@@ -591,8 +596,7 @@ func downloadConfigFiles(ctx context.Context, client stainless.Client, config Wo
591596
return nil
592597
}
593598

594-
// If contents differ, ask for confirmation
595-
shouldOverwrite, err := Confirm(nil, "", fmt.Sprintf("File %s already exists", path), "Do you want to overwrite it?", true)
599+
shouldOverwrite, _, err := group.Confirm(nil, "", fmt.Sprintf("File %s already exists", path), "Do you want to overwrite it?", true)
596600
if err != nil {
597601
return fmt.Errorf("failed to confirm file overwrite: %w", err)
598602
}

0 commit comments

Comments
 (0)