@@ -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,46 +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- Target : stainless .BuildTargetOutputGetParamsTarget (cmd .Value ("target" ).(string )),
73- Type : stainless .BuildTargetOutputGetParamsType (cmd .Value ("type" ).(string )),
74- Output : stainless .BuildTargetOutputGetParamsOutput (cmd .String ("output" )),
75- }
76- res , err := client .Builds .TargetOutputs .Get (
77- ctx ,
78- params ,
79- option .WithMiddleware (debugMiddleware (cmd .Bool ("debug" ))),
80- )
81- if err != nil {
82- return err
83- }
70+ wc := getWorkspace (ctx )
71+ downloadPaths , targets , _ := parseTargetPaths (wc , cmd .StringSlice ("target" ))
8472
85- json := gjson .Parse (res .RawJSON ())
86- format := cmd .Root ().String ("format" )
87- transform := cmd .Root ().String ("transform" )
88- if err := ShowJSON ("builds:target_outputs retrieve" , json , format , transform ); err != nil {
89- return err
73+ if len (targets ) == 0 {
74+ return fmt .Errorf ("at least one target must be specified" )
9075 }
9176
92- if cmd .Bool ("pull" ) {
93- group := console .Info ("Downloading output" )
77+ outputType := cmd .String ("type" )
78+ outputFormat := cmd .String ("output" )
79+ isPull := cmd .Bool ("pull" )
9480
95- // Check workspace config for target output path
96- targetDir := ""
97- wc := getWorkspace (ctx )
98- target := stainless .Target (cmd .Value ("target" ).(string ))
99- if targetConfig , ok := wc .Targets [target ]; ok && targetConfig .OutputPath != "" {
100- targetDir = targetConfig .OutputPath
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+ }
101104 }
102105
103- return build .PullOutput (
104- res .Output ,
105- res .URL ,
106- res .Ref ,
107- cmd .String ("branch" ),
108- targetDir ,
109- group )
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+ }
110116 }
111117
112118 return nil
0 commit comments