From 879c793ea17cf47d776cfc3a81ca512238494154 Mon Sep 17 00:00:00 2001 From: Eric Cheatham Date: Mon, 28 Mar 2022 15:07:32 -0500 Subject: [PATCH 1/2] Init a python app using apps init --- cmd/meroxa/root/apps/apps.go | 3 ++- cmd/meroxa/root/apps/init.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/meroxa/root/apps/apps.go b/cmd/meroxa/root/apps/apps.go index 37e6ac725..6663bae8c 100644 --- a/cmd/meroxa/root/apps/apps.go +++ b/cmd/meroxa/root/apps/apps.go @@ -27,10 +27,11 @@ import ( type Apps struct{} const ( + Python = "python" JavaScript = "javascript" GoLang = "golang" NodeJs = "nodejs" - LanguageNotSupportedError = "Currently, we support \"javascript\" and \"golang\"" + LanguageNotSupportedError = "Currently, we support \"javascript\", \"golang\", and \"python\"" ) var ( diff --git a/cmd/meroxa/root/apps/init.go b/cmd/meroxa/root/apps/init.go index 307dc4c47..2b7a05d27 100644 --- a/cmd/meroxa/root/apps/init.go +++ b/cmd/meroxa/root/apps/init.go @@ -6,10 +6,9 @@ import ( "fmt" "os/exec" - 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" + turbinejs "github.com/meroxa/cli/cmd/meroxa/turbine_cli/javascript" "github.com/meroxa/cli/log" turbine "github.com/meroxa/turbine/init" ) @@ -96,6 +95,14 @@ func (i *Init) Execute(ctx context.Context) error { err = turbine.Init(name, i.path) case "js", JavaScript, NodeJs: err = turbinejs.Init(ctx, i.logger, name, i.path) + case "py", Python: + cmd := exec.Command("turbine", "--generate", name, i.path) + stdout, err := cmd.CombinedOutput() + if err != nil { + i.logger.Error(ctx, string(stdout)) + return err + } + i.logger.Info(ctx, string(stdout)) default: return fmt.Errorf("language %q not supported. %s", lang, LanguageNotSupportedError) } From 3372902c33760b34ba9cd1656d95ab6cdb47e9f4 Mon Sep 17 00:00:00 2001 From: Eric Cheatham Date: Mon, 28 Mar 2022 17:22:20 -0500 Subject: [PATCH 2/2] add dir for python commands --- cmd/meroxa/root/apps/init.go | 9 ++------- cmd/meroxa/turbine_cli/python/init.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 cmd/meroxa/turbine_cli/python/init.go diff --git a/cmd/meroxa/root/apps/init.go b/cmd/meroxa/root/apps/init.go index 2b7a05d27..3e7f87b74 100644 --- a/cmd/meroxa/root/apps/init.go +++ b/cmd/meroxa/root/apps/init.go @@ -9,6 +9,7 @@ import ( "github.com/meroxa/cli/cmd/meroxa/builder" turbineCLI "github.com/meroxa/cli/cmd/meroxa/turbine_cli" 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" turbine "github.com/meroxa/turbine/init" ) @@ -96,13 +97,7 @@ func (i *Init) Execute(ctx context.Context) error { case "js", JavaScript, NodeJs: err = turbinejs.Init(ctx, i.logger, name, i.path) case "py", Python: - cmd := exec.Command("turbine", "--generate", name, i.path) - stdout, err := cmd.CombinedOutput() - if err != nil { - i.logger.Error(ctx, string(stdout)) - return err - } - i.logger.Info(ctx, string(stdout)) + err = turbinepy.Init(ctx, i.logger, name, i.path) default: return fmt.Errorf("language %q not supported. %s", lang, LanguageNotSupportedError) } diff --git a/cmd/meroxa/turbine_cli/python/init.go b/cmd/meroxa/turbine_cli/python/init.go new file mode 100644 index 000000000..c8f1d0bfa --- /dev/null +++ b/cmd/meroxa/turbine_cli/python/init.go @@ -0,0 +1,15 @@ +package turbinejs + +import ( + "context" + "os/exec" + + turbineCLI "github.com/meroxa/cli/cmd/meroxa/turbine_cli" + "github.com/meroxa/cli/log" +) + +func Init(ctx context.Context, l log.Logger, name, path string) error { + cmd := exec.Command("turbine", "--generate", name, path) + _, err := turbineCLI.RunCmdWithErrorDetection(ctx, cmd, l) + return err +}