Skip to content

Commit

Permalink
Update init command format and add a helpful link
Browse files Browse the repository at this point in the history
  • Loading branch information
janelletavares committed Jul 13, 2022
1 parent b8c9694 commit e0f92fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
12 changes: 11 additions & 1 deletion cmd/meroxa/root/apps/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 16 additions & 9 deletions cmd/meroxa/turbine_cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions log/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
const (
Successful = "successful"
Failed = "failed"
Warning = "warning"
)

type SpinnerLogger interface {
Expand Down Expand Up @@ -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)
Expand All @@ -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("⚡")
}

0 comments on commit e0f92fc

Please sign in to comment.