Skip to content

Commit 025db62

Browse files
committed
feat: fix builds:target-outputs --pull
1 parent 53df302 commit 025db62

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

pkg/cmd/buildtargetoutput.go

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ var buildsTargetOutputsRetrieve = cli.Command{
3434
Usage: "Branch name (defaults to main if not provided)",
3535
Value: "main",
3636
},
37-
&cli.StringFlag{
37+
&cli.StringSliceFlag{
3838
Name: "target",
39-
Usage: "SDK language target name",
39+
Usage: "SDK language target name(s). Can be specified multiple times.",
4040
},
4141
&cli.StringFlag{
4242
Name: "type",
@@ -67,30 +67,52 @@ func handleBuildsTargetOutputsRetrieve(ctx context.Context, cmd *cli.Command) er
6767
buildID = latestBuild.ID
6868
}
6969

70-
params := stainless.BuildTargetOutputGetParams{
71-
BuildID: buildID,
72-
}
73-
var resBytes []byte
74-
res, err := client.Builds.TargetOutputs.Get(
75-
ctx,
76-
params,
77-
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
78-
option.WithResponseBodyInto(&resBytes),
79-
)
80-
if err != nil {
81-
return err
82-
}
70+
wc := getWorkspace(ctx)
71+
downloadPaths, targets, _ := parseTargetPaths(wc, cmd.StringSlice("target"))
8372

84-
json := gjson.Parse(string(resBytes))
85-
format := cmd.Root().String("format")
86-
transform := cmd.Root().String("transform")
87-
if err := ShowJSON("builds:target_outputs retrieve", json, format, transform); err != nil {
88-
return err
73+
if len(targets) == 0 {
74+
return fmt.Errorf("at least one target must be specified")
8975
}
9076

91-
group := console.Info("Downloading output")
92-
if cmd.Bool("pull") {
93-
return build.PullOutput(res.Output, res.URL, res.Ref, cmd.String("branch"), "", group)
77+
outputType := cmd.String("type")
78+
outputFormat := cmd.String("output")
79+
isPull := cmd.Bool("pull")
80+
81+
for _, target := range targets {
82+
params := stainless.BuildTargetOutputGetParams{
83+
BuildID: buildID,
84+
Target: stainless.BuildTargetOutputGetParamsTarget(target),
85+
Type: stainless.BuildTargetOutputGetParamsType(outputType),
86+
Output: stainless.BuildTargetOutputGetParamsOutput(outputFormat),
87+
}
88+
res, err := client.Builds.TargetOutputs.Get(
89+
ctx,
90+
params,
91+
option.WithMiddleware(debugMiddleware(cmd.Bool("debug"))),
92+
)
93+
if err != nil {
94+
return fmt.Errorf("failed to get output for target %s: %v", target, err)
95+
}
96+
97+
if !isPull {
98+
json := gjson.Parse(res.RawJSON())
99+
format := cmd.Root().String("format")
100+
transform := cmd.Root().String("transform")
101+
if err := ShowJSON("builds:target_outputs retrieve", json, format, transform); err != nil {
102+
return err
103+
}
104+
}
105+
106+
if isPull {
107+
group := console.Info(fmt.Sprintf("Downloading %s", target))
108+
109+
// Get target output path from downloadPaths (which includes workspace config)
110+
targetDir := downloadPaths[target]
111+
112+
if err := build.PullOutput(res.Output, res.URL, res.Ref, cmd.String("branch"), targetDir, group); err != nil {
113+
return fmt.Errorf("failed to pull %s: %v", target, err)
114+
}
115+
}
94116
}
95117

96118
return nil

0 commit comments

Comments
 (0)