Skip to content

Commit

Permalink
Merge pull request #263 from meroxa/init-with-git
Browse files Browse the repository at this point in the history
initialize repository on apps init
  • Loading branch information
brettgoulder authored Feb 25, 2022
2 parents 326f3e7 + 42d4866 commit c795d6e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
21 changes: 20 additions & 1 deletion cmd/meroxa/root/apps/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ func (i *Init) ParseArgs(args []string) error {
return nil
}

func (i *Init) GitInit(ctx context.Context, path string) error {
if path == "" {
return errors.New("path is required")
}

cmd := exec.Command("git", "init", path)
_, err := cmd.CombinedOutput()
if err != nil {
return err
}

return nil
}

func (i *Init) Execute(ctx context.Context) error {
name := i.args.appName
lang := i.flags.Lang
Expand All @@ -79,7 +93,7 @@ func (i *Init) Execute(ctx context.Context) error {
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_cli", "generate", name)
cmd := exec.Command("npx", "turbine", "generate", name)
stdout, err := cmd.CombinedOutput()
if err != nil {
return err
Expand All @@ -89,5 +103,10 @@ func (i *Init) Execute(ctx context.Context) error {
return fmt.Errorf("language %q not supported. Currently, we support \"javascript\" and \"go\"", lang)
}

err := i.GitInit(ctx, i.path+"/"+name)
if err != nil {
return err
}

return nil
}
32 changes: 32 additions & 0 deletions cmd/meroxa/root/apps/init_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package apps

import (
"context"
"errors"
"os"
"testing"

"github.com/google/uuid"
"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/utils"
)
Expand Down Expand Up @@ -68,3 +71,32 @@ func TestInitAppFlags(t *testing.T) {
}
}
}

func TestGitInit(t *testing.T) {
testDir := os.TempDir() + "/tests" + uuid.New().String()

tests := []struct {
path string
err error
}{
{path: "", err: errors.New("path is required")},
{path: testDir, err: nil},
}

for _, tt := range tests {
cc := &Init{}
err := cc.GitInit(context.Background(), tt.path)

if err != nil && tt.err.Error() != err.Error() {
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err)
}

if tt.err == nil {
if _, err := os.Stat(testDir + "/.git"); os.IsNotExist(err) {
t.Fatalf("expected directory \"%s\" to be created", testDir)
}
}
}

os.RemoveAll(testDir)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ require (
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.42.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
Expand Down Expand Up @@ -609,7 +610,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da h1:qiPWuGGr+1GQE6s9NPSK8iggR/6x/V+0snIoOPYsBgc=
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da/go.mod h1:DvuJJ/w1Y59rG8UTDxsMk5U+UJXJwuvUgbiJSm9yhX8=
Expand Down Expand Up @@ -1274,8 +1274,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ google.golang.org/protobuf/types/descriptorpb
google.golang.org/protobuf/types/known/anypb
google.golang.org/protobuf/types/known/durationpb
google.golang.org/protobuf/types/known/timestamppb
# gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
## explicit; go 1.11
# gopkg.in/ini.v1 v1.62.0
## explicit
gopkg.in/ini.v1
Expand Down

0 comments on commit c795d6e

Please sign in to comment.