Skip to content

Commit e2a9285

Browse files
author
Bruce Hill
committed
Restore commented-out code, remove old config files when overwriting
workspace, and minor cleanups
1 parent bda55a9 commit e2a9285

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

pkg/cmd/init.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/pkg/browser"
1616
"github.com/stainless-api/stainless-api-cli/pkg/jsonflag"
1717
"github.com/stainless-api/stainless-api-go"
18+
"github.com/stainless-api/stainless-api-go/option"
1819
"github.com/urfave/cli/v3"
1920
)
2021

@@ -104,12 +105,13 @@ func handleInit(ctx context.Context, cmd *cli.Command) error {
104105
if err == nil && found {
105106
title := fmt.Sprintf("Existing workspace detected: %s (project: %s)", existingConfig.ConfigPath, existingConfig.Project)
106107
overwrite, err := Confirm(cmd, "", title, "Do you want to overwrite your existing workplace configuration?", true)
107-
if err != nil {
108+
if err != nil || !overwrite {
108109
return err
109110
}
110-
if !overwrite {
111-
return nil
111+
if err := os.Remove(existingConfig.ConfigPath); err != nil {
112+
return err
112113
}
114+
existingConfig = WorkspaceConfig{}
113115
}
114116

115117
orgs := fetchUserOrgs(cc.client, ctx)
@@ -279,19 +281,19 @@ func createProject(ctx context.Context, cmd *cli.Command, cc *apiCommandContext,
279281
info.Property("targets", fmt.Sprintf("%v", selectedTargets))
280282

281283
slug := nameToSlug(projectName)
282-
// _, err := cc.client.Projects.New(
283-
// ctx,
284-
// stainless.ProjectNewParams{
285-
// DisplayName: projectName,
286-
// Org: org,
287-
// Slug: slug,
288-
// Targets: selectedTargets,
289-
// },
290-
// option.WithMiddleware(cc.AsMiddleware()),
291-
// )
292-
// if err != nil {
293-
// return "", nil, err
294-
// }
284+
_, err := cc.client.Projects.New(
285+
ctx,
286+
stainless.ProjectNewParams{
287+
DisplayName: projectName,
288+
Org: org,
289+
Slug: slug,
290+
Targets: selectedTargets,
291+
},
292+
option.WithMiddleware(cc.AsMiddleware()),
293+
)
294+
if err != nil {
295+
return "", nil, err
296+
}
295297

296298
info.Success("Project created successfully")
297299

@@ -301,25 +303,30 @@ func createProject(ctx context.Context, cmd *cli.Command, cc *apiCommandContext,
301303
func initializeWorkspace(ctx context.Context, cmd *cli.Command, cc *apiCommandContext, projectSlug string, targets []stainless.Target) error {
302304
info := Info("Initializing workspace...")
303305

304-
openAPISpec := cmd.String("openapi-spec")
305-
if openAPISpec == "" {
306+
var openAPISpecPath string
307+
if cmd.IsSet("openapi-spec") {
308+
fmt.Printf("OAS Path: %s\n", openAPISpecPath)
309+
openAPISpecPath = cmd.String("openapi-spec")
310+
} else {
306311
var err error
307-
openAPISpec, err = chooseOpenAPISpecLocation()
312+
openAPISpecPath, err = chooseOpenAPISpecLocation()
308313
if err != nil {
309314
return err
310315
}
311316
}
312317

313-
stainlessConfig := cmd.String("stainless-config")
314-
if stainlessConfig == "" {
318+
var stainlessConfigPath string
319+
if cmd.IsSet("stainless-config") {
320+
stainlessConfigPath = cmd.String("stainless-config")
321+
} else {
315322
var err error
316-
stainlessConfig, err = chooseStainlessConfigLocation()
323+
stainlessConfigPath, err = chooseStainlessConfigLocation()
317324
if err != nil {
318325
return err
319326
}
320327
}
321328

322-
config, err := NewWorkspaceConfig(projectSlug, openAPISpec, stainlessConfig)
329+
config, err := NewWorkspaceConfig(projectSlug, openAPISpecPath, stainlessConfigPath)
323330
if err != nil {
324331
info.Error("Failed to create workspace config: %v", err)
325332
return fmt.Errorf("project created but workspace initialization failed: %v", err)

pkg/cmd/workspaceconfig.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,17 @@ func (config *WorkspaceConfig) Save() error {
107107
return encoder.Encode(config)
108108
}
109109

110-
func NewWorkspaceConfig(projectName, openAPISpec, stainlessConfig string) (WorkspaceConfig, error) {
111-
return NewWorkspaceConfigWithTargets(projectName, openAPISpec, stainlessConfig, nil)
112-
}
113-
114-
func NewWorkspaceConfigWithTargets(projectName, openAPISpec, stainlessConfig string, targets map[string]*TargetConfig) (WorkspaceConfig, error) {
110+
func NewWorkspaceConfig(projectName, openAPISpecPath, stainlessConfigPath string) (WorkspaceConfig, error) {
115111
dir, err := os.Getwd()
116112
if err != nil {
117113
return WorkspaceConfig{}, err
118114
}
119115

120116
return WorkspaceConfig{
121117
Project: projectName,
122-
OpenAPISpec: openAPISpec,
123-
StainlessConfig: stainlessConfig,
124-
Targets: targets,
118+
OpenAPISpec: openAPISpecPath,
119+
StainlessConfig: stainlessConfigPath,
120+
Targets: nil,
125121
ConfigPath: filepath.Join(dir, ".stainless", "workspace.json"),
126122
}, nil
127123
}

0 commit comments

Comments
 (0)