Skip to content

Commit 3aaa391

Browse files
committed
chore: attempt to fix merge conflicts
1 parent cf7e344 commit 3aaa391

File tree

10 files changed

+142
-269
lines changed

10 files changed

+142
-269
lines changed

pkg/cmd/auth.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ func authenticate(ctx context.Context, cmd *cli.Command, forceAuthentication boo
7171
}
7272

7373
group := console.Info("To authenticate, visit the verification URL")
74-
cc := getAPICommandContext(cmd)
75-
clientID := cmd.String("client-id")
74+
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
7675
scope := "*"
77-
authResult, err := startDeviceFlow(ctx, cmd, cc.client, clientID, scope, group)
76+
authResult, err := startDeviceFlow(ctx, cmd, client, cmd.String("client-id"), scope, group)
7877
if err != nil {
7978
return err
8079
}

pkg/cmd/build.go

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,82 +17,49 @@ import (
1717
"github.com/stainless-api/stainless-api-go/option"
1818

1919
"github.com/tidwall/gjson"
20-
"github.com/tidwall/sjson"
2120
"github.com/urfave/cli/v3"
2221
)
2322

2423
// parseTargetPaths processes target flags to extract target:path syntax with workspace config
2524
// Returns a map of target names to their custom paths
26-
func parseTargetPaths(workspaceConfig WorkspaceConfig) map[stainless.Target]string {
27-
targetPaths := make(map[stainless.Target]string)
25+
func parseTargetPaths(workspaceConfig WorkspaceConfig, targetsSlice []string) (downloadPaths map[stainless.Target]string, targets []stainless.Target) {
26+
downloadPaths = make(map[stainless.Target]string)
2827

2928
// Check workspace configuration for target paths if loaded
3029
for targetName, targetConfig := range workspaceConfig.Targets {
3130
if targetConfig.OutputPath != "" {
32-
targetPaths[stainless.Target(targetName)] = targetConfig.OutputPath
31+
downloadPaths[stainless.Target(targetName)] = targetConfig.OutputPath
3332
}
3433
}
3534

36-
// Get the current JSON body with all mutations applied
37-
body, _, _, err := jsonflag.ApplyMutations([]byte("{}"), []byte("{}"), []byte("{}"))
38-
if err != nil {
39-
return targetPaths // If we can't parse, return map with workspace paths
40-
}
41-
42-
// Check if there are any targets in the body
43-
targetsResult := gjson.GetBytes(body, "targets")
44-
if !targetsResult.Exists() {
45-
return targetPaths
46-
}
47-
48-
// Process the targets array
49-
var cleanTargets []string
50-
for _, targetResult := range targetsResult.Array() {
51-
target := targetResult.String()
35+
// Process the targets array from the CLI
36+
for _, target := range targetsSlice {
5237
cleanTarget, path := processSingleTarget(target)
53-
cleanTargets = append(cleanTargets, cleanTarget)
38+
targets = append(targets, cleanTarget)
5439
if path != "" {
5540
// Command line target:path overrides workspace configuration
56-
targetPaths[stainless.Target(cleanTarget)] = path
41+
downloadPaths[stainless.Target(cleanTarget)] = path
5742
}
5843
}
5944

60-
// Update the JSON body with cleaned targets
61-
if len(cleanTargets) > 0 {
62-
body, err = sjson.SetBytes(body, "targets", cleanTargets)
63-
if err != nil {
64-
return targetPaths
65-
}
66-
67-
// Clear mutations and re-apply the cleaned JSON
68-
jsonflag.ClearMutations()
69-
70-
// Re-register the cleaned body
71-
bodyObj := gjson.ParseBytes(body)
72-
bodyObj.ForEach(func(key, value gjson.Result) bool {
73-
jsonflag.Mutate(jsonflag.Body, key.String(), value.Value())
74-
return true
75-
})
76-
}
77-
78-
return targetPaths
45+
return downloadPaths, targets
7946
}
8047

8148
// processSingleTarget extracts path from target:path and returns clean target name and path
82-
func processSingleTarget(target string) (string, string) {
49+
func processSingleTarget(target string) (stainless.Target, string) {
8350
target = strings.TrimSpace(target)
8451
if !strings.Contains(target, ":") {
85-
return target, ""
52+
return stainless.Target(target), ""
8653
}
8754

8855
parts := strings.SplitN(target, ":", 2)
8956
if len(parts) != 2 {
90-
return target, ""
57+
return stainless.Target(target), ""
9158
}
9259

9360
targetName := strings.TrimSpace(parts[0])
9461
targetPath := strings.TrimSpace(parts[1])
95-
return targetName, targetPath
62+
return stainless.Target(targetName), targetPath
9663
}
9764

9865
var buildsCreate = cli.Command{
@@ -133,16 +100,6 @@ var buildsCreate = cli.Command{
133100
Name: "target",
134101
Usage: "Optional list of SDK targets to build. If not specified, all configured\ntargets will be built.",
135102
},
136-
&jsonflag.JSONStringFlag{
137-
Name: "target",
138-
Config: jsonflag.JSONConfig{
139-
Kind: jsonflag.Body,
140-
Path: "targets.-1",
141-
},
142-
Hidden: true,
143-
},
144-
&jsonflag.JSONStringFlag{,
145-
},
146103
},
147104
Action: handleBuildsCreate,
148105
HideHelpCommand: true,
@@ -176,37 +133,50 @@ var buildsCompare = cli.Command{
176133

177134
func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
178135
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
136+
137+
wc := WorkspaceConfig{}
138+
if _, err := wc.Find(); err != nil {
139+
console.Warn("%s", err)
140+
}
141+
179142
unusedArgs := cmd.Args().Slice()
180143
if len(unusedArgs) > 0 {
181144
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
182145
}
183146

184147
// Handle file flags by reading files and mutating JSON body
185-
if err := applyFileFlag(cmd, "openapi-spec", "revision.openapi\\.yml.content"); err != nil {
148+
if err := convertFileFlag(cmd, "openapi-spec", "revision.openapi\\.yml.content"); err != nil {
186149
return err
187150
}
188-
if err := applyFileFlag(cmd, "stainless-config", "revision.openapi\\.stainless\\.yml.content"); err != nil {
151+
if err := convertFileFlag(cmd, "stainless-config", "revision.openapi\\.stainless\\.yml.content"); err != nil {
189152
return err
190153
}
191154

192155
buildGroup := console.Info("Creating build...")
193156
params := stainless.BuildNewParams{}
194-
build, err := cc.client.Builds.New(
157+
if err := unmarshalStdinWithFlags(cmd, map[string]string{
158+
"targets": "targets",
159+
}, &params); err != nil {
160+
return err
161+
}
162+
163+
downloadPaths, targets := parseTargetPaths(wc, cmd.StringSlice("target"))
164+
params.Targets = targets
165+
166+
build, err := client.Builds.New(
195167
ctx,
196168
params,
197-
option.WithMiddleware(cc.AsMiddleware()),
169+
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
198170
)
199171
if err != nil {
200172
return err
201173
}
202174

203175
buildGroup.Property("build_id", build.ID)
204176

205-
downloadPaths := parseTargetPaths(cc.workspaceConfig)
206-
207177
if cmd.Bool("wait") {
208178
console.Spacer()
209-
model := tea.Model(buildCompletionModel{cbuild.NewModel(cc.client, ctx, *build, downloadPaths)})
179+
model := tea.Model(buildCompletionModel{cbuild.NewModel(client, ctx, *build, downloadPaths)})
210180
model, err = tea.NewProgram(model).Run()
211181
if err != nil {
212182
console.Warn(err.Error())

pkg/cmd/buildtargetoutput.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"context"
77
"fmt"
88

9-
"github.com/stainless-api/stainless-api-cli/pkg/console"
109
"github.com/stainless-api/stainless-api-cli/pkg/components/build"
10+
"github.com/stainless-api/stainless-api-cli/pkg/console"
1111
"github.com/stainless-api/stainless-api-go"
1212
"github.com/stainless-api/stainless-api-go/option"
1313
"github.com/tidwall/gjson"
@@ -59,7 +59,7 @@ func handleBuildsTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) er
5959

6060
buildID := cmd.String("build-id")
6161
if buildID == "" {
62-
latestBuild, err := getLatestBuild(ctx, cc.client, cmd.String("project"), cmd.String("branch"))
62+
latestBuild, err := getLatestBuild(ctx, client, cmd.String("project"), cmd.String("branch"))
6363
if err != nil {
6464
return fmt.Errorf("failed to get latest build: %v", err)
6565
}

pkg/cmd/configwatcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111

1212
type configChangedEvent struct{}
1313

14-
func waitTillConfigChanges(ctx context.Context, cmd *cli.Command, cc *apiCommandContext) error {
15-
openapiSpecPath := cc.workspaceConfig.OpenAPISpec
14+
func waitTillConfigChanges(ctx context.Context, cmd *cli.Command, wc WorkspaceConfig) error {
15+
openapiSpecPath := wc.OpenAPISpec
1616
if cmd.IsSet("openapi-spec") {
1717
openapiSpecPath = cmd.String("openapi-spec")
1818
}
19-
stainlessConfigPath := cc.workspaceConfig.StainlessConfig
19+
stainlessConfigPath := wc.StainlessConfig
2020
if cmd.IsSet("stainless-config") {
2121
stainlessConfigPath = cmd.String("stainless-config")
2222
}

pkg/cmd/dev.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
7070
os.Stdout.Sync()
7171
}
7272

73-
cc := getAPICommandContext(cmd)
73+
client := stainless.NewClient(getDefaultRequestOptions(cmd)...)
74+
75+
wc := WorkspaceConfig{}
76+
if _, err := wc.Find(); err != nil {
77+
console.Warn("%s", err)
78+
}
7479

7580
gitUser, err := getGitUsername()
7681
if err != nil {
@@ -91,7 +96,7 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
9196

9297
// Phase 2: Language selection
9398
var selectedTargets []string
94-
targetInfos := getAvailableTargetInfo(ctx, cc.client, cmd.String("project"), cc.workspaceConfig)
99+
targetInfos := getAvailableTargetInfo(ctx, client, cmd.String("project"), wc)
95100
if cmd.IsSet("target") {
96101
selectedTargets = cmd.StringSlice("target")
97102
for _, target := range selectedTargets {
@@ -126,7 +131,7 @@ func runPreview(ctx context.Context, cmd *cli.Command) error {
126131
}
127132

128133
// Start the build process
129-
if err := runDevBuild(ctx, cc, cmd, selectedBranch, targets); err != nil {
134+
if err := runDevBuild(ctx, client, wc, cmd, selectedBranch, targets); err != nil {
130135
if errors.Is(err, build.ErrUserCancelled) {
131136
return nil
132137
}
@@ -202,12 +207,12 @@ func chooseSelectedTargets(targetInfos []TargetInfo) ([]string, error) {
202207
return selectedTargets, nil
203208
}
204209

205-
func runDevBuild(ctx context.Context, cc *apiCommandContext, cmd *cli.Command, branch string, languages []stainless.Target) error {
210+
func runDevBuild(ctx context.Context, client stainless.Client, wc WorkspaceConfig, cmd *cli.Command, branch string, languages []stainless.Target) error {
206211
// Handle file flags by reading files and mutating JSON body
207-
if err := applyFileFlag(cmd, "openapi-spec", "revision.openapi\\.yml.content"); err != nil {
212+
if err := convertFileFlag(cmd, "openapi-spec", "revision.openapi\\.yml.content"); err != nil {
208213
return err
209214
}
210-
if err := applyFileFlag(cmd, "stainless-config", "revision.openapi\\.stainless\\.yml.content"); err != nil {
215+
if err := convertFileFlag(cmd, "stainless-config", "revision.openapi\\.stainless\\.yml.content"); err != nil {
211216
return err
212217
}
213218

@@ -220,16 +225,20 @@ func runDevBuild(ctx context.Context, cc *apiCommandContext, cmd *cli.Command, b
220225
}
221226

222227
downloads := make(map[stainless.Target]string)
223-
for targetName, targetConfig := range cc.workspaceConfig.Targets {
228+
for targetName, targetConfig := range wc.Targets {
224229
downloads[stainless.Target(targetName)] = targetConfig.OutputPath
225230
}
226231

227232
model := dev.NewModel(
228-
cc.client,
233+
client,
229234
ctx,
230235
branch,
231236
func() (*stainless.Build, error) {
232-
build, err := cc.client.Builds.New(ctx, buildReq, option.WithMiddleware(cc.AsMiddleware()))
237+
build, err := client.Builds.New(
238+
ctx,
239+
buildReq,
240+
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
241+
)
233242
if err != nil {
234243
return nil, fmt.Errorf("failed to create build: %v", err)
235244
}
@@ -291,16 +300,16 @@ type GenerateSpecParams struct {
291300
} `json:"source"`
292301
}
293302

294-
func getDiagnostics(ctx context.Context, cmd *cli.Command, cc *apiCommandContext) ([]stainless.BuildDiagnostic, error) {
303+
func getDiagnostics(ctx context.Context, cmd *cli.Command, client stainless.Client, wc WorkspaceConfig) ([]stainless.BuildDiagnostic, error) {
295304
var specParams GenerateSpecParams
296305
if cmd.IsSet("project") {
297306
specParams.Project = cmd.String("project")
298307
} else {
299-
specParams.Project = cc.workspaceConfig.Project
308+
specParams.Project = wc.Project
300309
}
301310
specParams.Source.Type = "upload"
302311

303-
configPath := cc.workspaceConfig.StainlessConfig
312+
configPath := wc.StainlessConfig
304313
if cmd.IsSet("stainless-config") {
305314
configPath = cmd.String("stainless-config")
306315
} else if configPath == "" {
@@ -313,7 +322,7 @@ func getDiagnostics(ctx context.Context, cmd *cli.Command, cc *apiCommandContext
313322
}
314323
specParams.Source.StainlessConfig = string(stainlessConfig)
315324

316-
oasPath := cc.workspaceConfig.OpenAPISpec
325+
oasPath := wc.OpenAPISpec
317326
if cmd.IsSet("openapi-spec") {
318327
oasPath = cmd.String("openapi-spec")
319328
} else if oasPath == "" {
@@ -327,7 +336,13 @@ func getDiagnostics(ctx context.Context, cmd *cli.Command, cc *apiCommandContext
327336
specParams.Source.OpenAPISpec = string(openAPISpec)
328337

329338
var result []byte
330-
err = cc.client.Post(ctx, "api/generate/spec", specParams, &result, option.WithMiddleware(cc.AsMiddleware()))
339+
err = client.Post(
340+
ctx,
341+
"api/generate/spec",
342+
specParams,
343+
&result,
344+
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
345+
)
331346
if err != nil {
332347
return nil, err
333348
}

0 commit comments

Comments
 (0)