@@ -265,6 +265,11 @@ func handleInit(ctx context.Context, cmd *cli.Command) error {
265265 return fmt .Errorf ("failed to get Stainless config form: %v" , err )
266266 }
267267 if downloadConfig {
268+ config .StainlessConfig = "./stainless.yml"
269+ err = config .Save ()
270+ if err != nil {
271+ return fmt .Errorf ("workspace update failed: %v" , err )
272+ }
268273 if err := downloadStainlessConfig (ctx , cc .client , slug , & config ); err != nil {
269274 return fmt .Errorf ("project created but config download failed: %v" , err )
270275 }
@@ -376,7 +381,11 @@ func nameToSlug(name string) string {
376381
377382// downloadStainlessConfig downloads the stainless config file for a project
378383func downloadStainlessConfig (ctx context.Context , client stainless.Client , slug string , config * WorkspaceConfig ) error {
379- stainlessConfig := "stainless.yml"
384+ stainlessConfig := config .StainlessConfig
385+ if config .StainlessConfig == "" {
386+ return nil
387+ }
388+
380389 group := Info ("Downloading Stainless config..." )
381390
382391 params := stainless.ProjectConfigGetParams {
@@ -412,23 +421,12 @@ func downloadStainlessConfig(ctx context.Context, client stainless.Client, slug
412421 content = try .Content
413422 }
414423
415- // Write the config to file
416424 err = os .WriteFile (stainlessConfig , []byte (content ), 0644 )
417425 if err != nil {
418426 group .Error ("Failed to save project config to %s: %v" , stainlessConfig , err )
419427 return fmt .Errorf ("config save failed: %v" , err )
420428 }
421429
422- // Update workspace config with stainless_config path
423- if config != nil {
424- config .StainlessConfig = stainlessConfig
425- err = config .Save ()
426- if err != nil {
427- Error ("Failed to update workspace config with stainless config path: %v" , err )
428- return fmt .Errorf ("workspace update failed: %v" , err )
429- }
430- }
431-
432430 group .Success ("Stainless config downloaded to %s" , stainlessConfig )
433431 return nil
434432}
0 commit comments