@@ -29,19 +29,15 @@ type BuildTargetInfo struct {
2929 status stainless.BuildTargetStatus
3030}
3131
32- // parseTargetPaths processes target flags to extract target:path syntax
32+ // parseTargetPaths processes target flags to extract target:path syntax with workspace config
3333// Returns a map of target names to their custom paths
34- func parseTargetPaths () map [string ]string {
34+ func parseTargetPaths (workspaceConfig WorkspaceConfig ) map [string ]string {
3535 targetPaths := make (map [string ]string )
3636
37- // First, check workspace configuration for target paths
38- var config WorkspaceConfig
39- found , err := config .Find ()
40- if err == nil && found && config .Targets != nil {
41- for targetName , targetConfig := range config .Targets {
42- if targetConfig .OutputPath != "" {
43- targetPaths [targetName ] = targetConfig .OutputPath
44- }
37+ // Check workspace configuration for target paths if loaded
38+ for targetName , targetConfig := range workspaceConfig .Targets {
39+ if targetConfig .OutputPath != "" {
40+ targetPaths [targetName ] = targetConfig .OutputPath
4541 }
4642 }
4743
@@ -446,26 +442,13 @@ var buildsCompare = cli.Command{
446442}
447443
448444func handleBuildsCreate (ctx context.Context , cmd * cli.Command ) error {
449- targetPaths := parseTargetPaths ()
450-
451- // Check workspace config for targets
452- var config WorkspaceConfig
453- hasWorkspaceTargets := false
454- found , err := config .Find ()
455- if err == nil && found && config .Targets != nil && len (config .Targets ) > 0 {
456- hasWorkspaceTargets = true
457- // Merge workspace target paths with command line target paths
458- for targetName , targetConfig := range config .Targets {
459- if _ , exists := targetPaths [targetName ]; ! exists && targetConfig .OutputPath != "" {
460- targetPaths [targetName ] = targetConfig .OutputPath
461- }
462- }
463- }
464-
465445 cc , err := getAPICommandContextWithWorkspaceDefaults (cmd )
466446 if err != nil {
467447 return err
468448 }
449+
450+ // Parse target paths using cached workspace config
451+ targetPaths := parseTargetPaths (cc .workspaceConfig )
469452 buildGroup := Info ("Creating build..." )
470453 params := stainless.BuildNewParams {}
471454 res , err := cc .client .Builds .New (
@@ -488,8 +471,8 @@ func handleBuildsCreate(ctx context.Context, cmd *cli.Command) error {
488471 }
489472
490473 // Pull if explicitly set via --pull flag, or if workspace has configured targets and --pull wasn't explicitly set to false
491- shouldPull := cmd .Bool ("pull" ) || (hasWorkspaceTargets && ! cmd .IsSet ("pull" ))
492-
474+ shouldPull := cmd .Bool ("pull" ) || (cc . HasWorkspaceTargets () && ! cmd .IsSet ("pull" ))
475+
493476 if shouldPull {
494477 pullGroup := Info ("Downloading build outputs..." )
495478 if err := pullBuildOutputs (context .TODO (), cc .client , * res , targetPaths , & pullGroup ); err != nil {
@@ -779,9 +762,10 @@ func handleBuildsCompare(ctx context.Context, cmd *cli.Command) error {
779762// getAPICommandWithWorkspaceDefaults applies workspace defaults before initializing API command
780763func getAPICommandContextWithWorkspaceDefaults (cmd * cli.Command ) (* apiCommandContext , error ) {
781764 cc := getAPICommandContext (cmd )
782- var config WorkspaceConfig
783- found , err := config .Find ()
784- if err == nil && found {
765+
766+ // Use cached workspace config if available
767+ if cc .workspaceConfig .ConfigPath != "" {
768+ config := cc .workspaceConfig
785769 // Get the directory containing the workspace config file
786770 configDir := filepath .Dir (config .ConfigPath )
787771
@@ -805,5 +789,5 @@ func getAPICommandContextWithWorkspaceDefaults(cmd *cli.Command) (*apiCommandCon
805789 jsonflag .Mutate (jsonflag .Body , "revision.openapi\\ .stainless\\ .yml.content" , string (content ))
806790 }
807791 }
808- return cc , err
792+ return cc , nil
809793}
0 commit comments