From 0867e7f725c0ebd6028a6d8d5e1c035f5ac80241 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 22 Sep 2025 13:59:44 +0100 Subject: [PATCH 1/2] convert: improve logging --- commands/project_convert.go | 41 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/commands/project_convert.go b/commands/project_convert.go index 58114ff..62fb066 100644 --- a/commands/project_convert.go +++ b/commands/project_convert.go @@ -2,11 +2,11 @@ package commands import ( "fmt" - "io" "log" "os" "path/filepath" + "github.com/fatih/color" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/symfony-cli/terminal" @@ -127,8 +127,24 @@ func runPlatformShConvert(cmd *cobra.Command) error { return fmt.Errorf("could not normalize project workspace path: %w", err) } - // Disable log for lib-sun - log.Default().SetOutput(io.Discard) + upsunDir := filepath.Join(cwd, ".upsun") + configPath := filepath.Join(upsunDir, "config.yaml") + stat, err := os.Stat(configPath) + if err == nil && !stat.IsDir() { + fmt.Fprintln(cmd.ErrOrStderr(), "The file already exists:", color.YellowString(configPath)) + if !viper.GetBool("yes") { + if viper.GetBool("no-interaction") { + return fmt.Errorf("use the -y option to overwrite the file") + } + + if !terminal.AskConfirmation("Do you want to overwrite it?", true) { + return nil + } + } + } + + // Override lib-sun's log output to stderr. + log.Default().SetOutput(cmd.ErrOrStderr()) // Find config files configFiles, err := detector.FindConfig(cwd) @@ -159,31 +175,16 @@ func runPlatformShConvert(cmd *cobra.Command) error { readers.ReplaceAllEntry(&metaConfig.Applications, "shared", "storage") readers.RemoveAllEntry(&metaConfig.Applications, "disk") - upsunDir := filepath.Join(cwd, ".upsun") if err := os.MkdirAll(upsunDir, os.ModePerm); err != nil { return fmt.Errorf("could not create .upsun directory: %w", err) } - configPath := filepath.Join(upsunDir, "config.yaml") - stat, err := os.Stat(configPath) - if err == nil && !stat.IsDir() { - cmd.Printf("The file %v already exists.\n", configPath) - if !viper.GetBool("yes") { - if viper.GetBool("no-interaction") { - return fmt.Errorf("use the -y option to overwrite the file") - } - - if !terminal.AskConfirmation("Do you want to overwrite it?", true) { - return nil - } - } - } writers.GenerateUpsunConfigFile(metaConfig, configPath) // Move extra config utils.TransferConfigCustom(cwd, upsunDir) - cmd.Println("Your configuration was successfully converted to the Upsun format.") - cmd.Printf("Check the generated files in %v\n", upsunDir) + fmt.Fprintln(cmd.ErrOrStderr(), "Your configuration was successfully converted to the Upsun format.") + fmt.Fprintln(cmd.ErrOrStderr(), "Check the generated files in:", color.GreenString(upsunDir)) return nil } From baa80bb27ede30d01d3f2e018af2d277f46039e9 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 22 Sep 2025 18:01:44 +0100 Subject: [PATCH 2/2] Additional logging --- commands/project_convert.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/project_convert.go b/commands/project_convert.go index 62fb066..b7b03fc 100644 --- a/commands/project_convert.go +++ b/commands/project_convert.go @@ -165,23 +165,30 @@ func runPlatformShConvert(cmd *cobra.Command) error { readers.ReadRoutes(&metaConfig, configFiles[entity.PSH_ROUTE]) // Remove size and resources entries + fmt.Fprintln(cmd.ErrOrStderr(), "Removing any `size`, `resources` or `disk` keys.") + fmt.Fprintln(cmd.ErrOrStderr(), + "Upsun disk sizes are set using Console or the "+color.GreenString("upsun resources:set")+" command.") readers.RemoveAllEntry(&metaConfig.Services, "size") readers.RemoveAllEntry(&metaConfig.Applications, "size") readers.RemoveAllEntry(&metaConfig.Services, "resources") readers.RemoveAllEntry(&metaConfig.Applications, "resources") + readers.RemoveAllEntry(&metaConfig.Applications, "disk") + readers.RemoveAllEntry(&metaConfig.Services, "disk") // Fix storage to match Upsun format + fmt.Fprintln(cmd.ErrOrStderr(), "Replacing mount types (`local` becomes `instance`, and `shared` becomes `storage`).") readers.ReplaceAllEntry(&metaConfig.Applications, "local", "instance") readers.ReplaceAllEntry(&metaConfig.Applications, "shared", "storage") - readers.RemoveAllEntry(&metaConfig.Applications, "disk") if err := os.MkdirAll(upsunDir, os.ModePerm); err != nil { return fmt.Errorf("could not create .upsun directory: %w", err) } + fmt.Fprintln(cmd.ErrOrStderr(), "Creating combined configuration file.") writers.GenerateUpsunConfigFile(metaConfig, configPath) // Move extra config + fmt.Fprintln(cmd.ErrOrStderr(), "Copying additional files if necessary.") utils.TransferConfigCustom(cwd, upsunDir) fmt.Fprintln(cmd.ErrOrStderr(), "Your configuration was successfully converted to the Upsun format.")