diff --git a/cmd/meroxa/root/apps/init.go b/cmd/meroxa/root/apps/init.go index 2d3c87a09..eb7b6285c 100644 --- a/cmd/meroxa/root/apps/init.go +++ b/cmd/meroxa/root/apps/init.go @@ -126,30 +126,40 @@ func (i *Init) Execute(ctx context.Context) error { return err } - i.logger.Infof(ctx, "Initializing application %q in %q...", name, i.path) + i.logger.StartSpinner("\t", fmt.Sprintf("Initializing application %q in %q...", name, i.path)) switch lang { case "go", GoLang: err = turbine.Init(name, i.path) if err != nil { + i.logger.StopSpinnerWithStatus("\t", log.Failed) return err } + i.logger.StopSpinnerWithStatus("Application directory created!", log.Successful) err = turbineCLI.GoInit(ctx, i.logger, i.path+"/"+name, i.flags.SkipModInit, i.flags.ModVendor) case "js", JavaScript, NodeJs: err = turbinejs.Init(ctx, i.logger, name, i.path) case "py", Python3, Python: err = turbinepy.Init(ctx, i.logger, name, i.path) default: + i.logger.StopSpinnerWithStatus("\t", log.Failed) return fmt.Errorf("language %q not supported. %s", lang, LanguageNotSupportedError) } if err != nil { + i.logger.StopSpinnerWithStatus("\t", log.Failed) return err } + if lang != "go" && lang != GoLang { + i.logger.StopSpinnerWithStatus("Application directory created!", log.Successful) + } + i.logger.StartSpinner("\t", "Running git initialization...") err = i.GitInit(ctx, i.path+"/"+name) if err != nil { + i.logger.StopSpinnerWithStatus("\t", log.Failed) return err } + i.logger.StopSpinnerWithStatus("Git initialized successfully!", log.Successful) i.logger.Infof(ctx, "Turbine Data Application successfully initialized!\n"+ "You can start interacting with Meroxa in your app located at \"%s/%s\".\n"+ "Your Application will not be visible in the Meroxa Dashboard until after deployment.", i.path, name) diff --git a/cmd/meroxa/turbine_cli/utils.go b/cmd/meroxa/turbine_cli/utils.go index ab3cc3ae4..cfb99c72e 100644 --- a/cmd/meroxa/turbine_cli/utils.go +++ b/cmd/meroxa/turbine_cli/utils.go @@ -244,48 +244,54 @@ func GetGitSha(appPath string) (string, error) { } func GoInit(ctx context.Context, l log.Logger, appPath string, skipInit, vendor bool) error { + l.StartSpinner("\t", "Running golang module initializing...") + skipLog := "skipping go module initialization\n\tFor guidance, visit https://docs.meroxa.com/beta-overview#common-errors" goPath := os.Getenv("GOPATH") if goPath == "" { - l.Warnf(ctx, "$GOPATH not set up; skipping go module initialization") + l.StopSpinnerWithStatus("$GOPATH not set up; "+skipLog, log.Warning) return nil } - i := strings.Index(appPath, goPath) + i := strings.Index(appPath, goPath+"/src") if i == -1 || i != 0 { - l.Warnf(ctx, "%s is not under $GOPATH; skipping go module initialization", appPath) + l.StopSpinnerWithStatus(fmt.Sprintf("%s is not under $GOPATH/src; %s", appPath, skipLog), log.Warning) return nil } // temporarily switching to the app's directory pwd, err := switchToAppDirectory(appPath) if err != nil { + l.StopSpinnerWithStatus("\t", log.Failed) return err } // initialize the user's module err = SetModuleInitInAppJSON(appPath, skipInit) if err != nil { + l.StopSpinnerWithStatus("\t", log.Failed) return err } if !skipInit { - l.Info(ctx, "Initializing the application's go module...") cmd := exec.Command("go", "mod", "init") output, err := cmd.CombinedOutput() if err != nil { - l.Error(ctx, string(output)) + l.StopSpinnerWithStatus(fmt.Sprintf("\t%s", string(output)), log.Failed) return err } + l.StopSpinnerWithStatus("go mod init succeeded!", log.Successful) + l.StartSpinner("\t", "Getting latest turbine-go and turbine-go/running dependencies...") cmd = exec.Command("go", "get", "github.com/meroxa/turbine-go") output, err = cmd.CombinedOutput() if err != nil { - l.Error(ctx, string(output)) + l.StopSpinnerWithStatus(fmt.Sprintf("\t%s", string(output)), log.Failed) return err } cmd = exec.Command("go", "get", "github.com/meroxa/turbine-go/runner") output, err = cmd.CombinedOutput() if err != nil { - l.Error(ctx, string(output)) + l.StopSpinnerWithStatus(fmt.Sprintf("\t%s", string(output)), log.Failed) return err } + l.StopSpinnerWithStatus("Got latest turbine-go and turbine-go/running dependencies successfully!", log.Successful) // download dependencies err = SetVendorInAppJSON(appPath, vendor) @@ -299,12 +305,13 @@ func GoInit(ctx context.Context, l log.Logger, appPath string, skipInit, vendor cmd = exec.Command("go", "mod", "vendor") } depsLog += "..." - l.Info(ctx, depsLog) + l.StartSpinner("\t", depsLog) output, err = cmd.CombinedOutput() if err != nil { - l.Error(ctx, string(output)) + l.StopSpinnerWithStatus(fmt.Sprintf("\t%s", string(output)), log.Failed) return err } + l.StopSpinnerWithStatus("Downdloaded all other dependencies successfully!", log.Successful) } return os.Chdir(pwd) diff --git a/log/spinner.go b/log/spinner.go index e1baa46f7..d1d8c3425 100644 --- a/log/spinner.go +++ b/log/spinner.go @@ -14,6 +14,7 @@ import ( const ( Successful = "successful" Failed = "failed" + Warning = "warning" ) type SpinnerLogger interface { @@ -50,6 +51,8 @@ func (l *spinnerLogger) StopSpinnerWithStatus(msg, status string) { msg = fmt.Sprintf("\t%s %s", l.FailedMark(), msg) } else if status == Successful { msg = fmt.Sprintf("\t%s %s", l.SuccessfulCheck(), msg) + } else if status == Warning { + msg = fmt.Sprintf("\t%s %s", l.WarningMark(), msg) } l.s.Stop() l.l.Printf(msg) @@ -62,3 +65,7 @@ func (l *spinnerLogger) SuccessfulCheck() string { func (l *spinnerLogger) FailedMark() string { return color.New(color.FgRed).Sprintf("x") } + +func (l *spinnerLogger) WarningMark() string { + return color.New(color.FgYellow).Sprintf("⚡") +}