Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(turbine): Path should always be converted to absolute #284

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ func (d *Deploy) Execute(ctx context.Context) error {
return err
}

d.path = turbineCLI.GetPath(d.flags.Path)
d.path, err = turbineCLI.GetPath(d.flags.Path)
if err != nil {
return err
}
d.lang, err = turbineCLI.GetLangFromAppJSON(d.path)
if err != nil {
return err
Expand Down
12 changes: 8 additions & 4 deletions cmd/meroxa/root/apps/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,24 @@ func (i *Init) Execute(ctx context.Context) error {
name := i.args.appName
lang := i.flags.Lang

i.path = turbineCLI.GetPath(i.flags.Path)
var err error
i.path, err = turbineCLI.GetPath(i.flags.Path)
if err != nil {
return err
}

i.logger.Infof(ctx, "Initializing application %q in %q...", name, i.path)
switch lang {
case "go", GoLang:
err := turbine.Init(name, i.path)
err = turbine.Init(name, i.path)
if err != nil {
return err
}
i.logger.Infof(ctx, "Application successfully initialized!\n"+
"You can start interacting with Meroxa in your app located at \"%s/%s\"", i.path, name)
case "js", JavaScript, NodeJs:
cmd := exec.Command("npx", "turbine", "generate", name, i.path)
stdout, err := cmd.CombinedOutput()
stdout, err := cmd.CombinedOutput() //nolint:govet
if err != nil {
i.logger.Error(ctx, string(stdout))
return err
Expand All @@ -105,7 +109,7 @@ func (i *Init) Execute(ctx context.Context) error {
return fmt.Errorf("language %q not supported. %s", lang, LanguageNotSupportedError)
}

err := i.GitInit(ctx, i.path+"/"+name)
err = i.GitInit(ctx, i.path+"/"+name)
if err != nil {
return err
}
Expand Down
18 changes: 6 additions & 12 deletions cmd/meroxa/root/apps/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ package apps
import (
"context"
"fmt"
"path/filepath"

turbineGo "github.com/meroxa/cli/cmd/meroxa/turbine_cli/golang"

turbineJS "github.com/meroxa/cli/cmd/meroxa/turbine_cli/javascript"

"github.com/meroxa/cli/cmd/meroxa/builder"
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"
"github.com/meroxa/cli/log"
)

Expand Down Expand Up @@ -72,13 +69,10 @@ func (r *Run) Flags() []builder.Flag {
}

func (r *Run) Execute(ctx context.Context) error {
r.path = turbineCLI.GetPath(r.flags.Path)
if r.path == "." || r.path == "" {
var err error
r.path, err = filepath.Abs(".")
if err != nil {
return err
}
var err error
r.path, err = turbineCLI.GetPath(r.flags.Path)
if err != nil {
return err
}
lang, err := turbineCLI.GetLang(r.flags.Lang, r.path)
if err != nil {
Expand Down
13 changes: 9 additions & 4 deletions cmd/meroxa/turbine_cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"

Expand All @@ -18,11 +19,15 @@ type AppConfig struct {
Language string `json:"language"`
}

func GetPath(pwd string) string {
if pwd != "" {
return pwd
func GetPath(flag string) (string, error) {
if flag == "." || flag == "" {
var err error
flag, err = filepath.Abs(".")
if err != nil {
return "", err
}
}
return "."
return flag, nil
}

// GetLang will return language defined either by `--lang` or the one defined by user in the app.json.
Expand Down