Skip to content

Commit

Permalink
Tweaks to init and run (#293)
Browse files Browse the repository at this point in the history
* Tweaks
  • Loading branch information
janelletavares authored Mar 31, 2022
1 parent 25dd8b8 commit 58ed05b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
5 changes: 4 additions & 1 deletion cmd/meroxa/root/apps/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
turbineCLI "github.com/meroxa/cli/cmd/meroxa/turbine_cli"
turbineGo "github.com/meroxa/cli/cmd/meroxa/turbine_cli/golang"
turbineJS "github.com/meroxa/cli/cmd/meroxa/turbine_cli/javascript"
turbinepy "github.com/meroxa/cli/cmd/meroxa/turbine_cli/python"
"github.com/meroxa/cli/log"
)

Expand Down Expand Up @@ -83,7 +84,9 @@ func (r *Run) Execute(ctx context.Context) error {
case GoLang:
return turbineGo.Run(ctx, r.path, r.logger)
case "js", JavaScript, NodeJs:
return turbineJS.Build(ctx, r.logger)
return turbineJS.Build(ctx, r.logger, r.path)
case "py", Python:
return turbinepy.Run(ctx, r.logger, r.path)
default:
return fmt.Errorf("language %q not supported. %s", lang, LanguageNotSupportedError)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/turbine_cli/javascript/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
)

// Build calls turbine-js to build an application.
func Build(ctx context.Context, l log.Logger) error {
func Build(ctx context.Context, l log.Logger, path string) error {
// TODO: Handle the requirement of https://github.com/meroxa/turbine-js.git being installed
// cd into the path first
cmd := exec.Command("npx", "turbine", "test")
cmd := exec.Command("npx", "turbine", "test", path)
_, err := turbinecli.RunCmdWithErrorDetection(ctx, cmd, l)
return err
}
4 changes: 2 additions & 2 deletions cmd/meroxa/turbine_cli/python/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package turbinejs
package turbinepy

import (
"context"
Expand All @@ -9,7 +9,7 @@ import (
)

func Init(ctx context.Context, l log.Logger, name, path string) error {
cmd := exec.Command("turbine", "--generate", name, path)
cmd := exec.Command("turbine-py", "--generate", name, path)
_, err := turbineCLI.RunCmdWithErrorDetection(ctx, cmd, l)
return err
}
20 changes: 20 additions & 0 deletions cmd/meroxa/turbine_cli/python/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package turbinepy

import (
"context"
"os/exec"
"path/filepath"

turbineCLI "github.com/meroxa/cli/cmd/meroxa/turbine_cli"
"github.com/meroxa/cli/log"
)

func Run(ctx context.Context, l log.Logger, path string) error {
f, err := filepath.Abs(filepath.Join(path, "main.py"))
if err != nil {
return err
}
cmd := exec.Command("python3", f)
_, err = turbineCLI.RunCmdWithErrorDetection(ctx, cmd, l)
return err
}
22 changes: 16 additions & 6 deletions cmd/meroxa/turbine_cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,23 @@ func RunCmdWithErrorDetection(ctx context.Context, cmd *exec.Cmd, l log.Logger)
cmd.Stdout = stdout
cmd.Stderr = stderr
err := cmd.Run()
successMsg := stdout.String()
errMsg := stderr.String()
if err != nil || errMsg != "" {
return "", errors.New(successMsg + errMsg)
stdOutMsg := stdout.String()
stdErrMsg := stderr.String()
if err != nil || stdErrMsg != "" {
var errMsg, errLog string
if err != nil {
errMsg = err.Error()
}
errLog = stdOutMsg
if stdErrMsg != "" {
errLog += stdErrMsg
} else if errMsg != "" {
errLog = errMsg
}
return "", errors.New(errLog)
}
l.Info(ctx, successMsg)
return successMsg, nil
l.Info(ctx, stdOutMsg)
return stdOutMsg, nil
}

// CreateTarAndZipFile creates a .tar.gz file from `src` on current directory.
Expand Down

0 comments on commit 58ed05b

Please sign in to comment.