Skip to content

Commit

Permalink
fix: go mod tidy before finish create project
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidayat Hamir committed Feb 7, 2024
1 parent 0f8ad3f commit 6581478
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ go install github.com/spacetronot-research-team/erago@latest
or you can define your prefered version.

```shell
go install github.com/spacetronot-research-team/erago@v0.0.11
go install github.com/spacetronot-research-team/erago@v0.0.12
```

Or you can download erago binary from [release page](https://github.com/spacetronot-research-team/erago/releases).
Expand Down
17 changes: 2 additions & 15 deletions cmd/createdomain/create_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/iancoleman/strcase"
"github.com/spacetronot-research-team/erago/cmd/createdomain/template"
"github.com/spacetronot-research-team/erago/common/gomod"
)

// CreateDomain is main func to create new domain.
Expand Down Expand Up @@ -62,7 +63,7 @@ func CreateDomain(domain string) {
}

log.Println("run go mod tidy")
if err := runGoModTidy(); err != nil {
if err := gomod.RunGoModTidy(); err != nil {
log.Fatal(fmt.Errorf("err run go mod tidy: %v", err))
}

Expand Down Expand Up @@ -199,17 +200,3 @@ func generateRepositoryTemplate(domain string, varErr1 string, varErr2 string) e

return nil
}

func runGoModTidy() error {
cmd := exec.Command("go", "mod", "tidy")
stdout, err := cmd.Output()
if err != nil {
return err
}

if string(stdout) != "" {
fmt.Println(string(stdout))
}

return nil
}
6 changes: 6 additions & 0 deletions cmd/createproject/create_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"

"github.com/spacetronot-research-team/erago/cmd/createdomain"
"github.com/spacetronot-research-team/erago/common/gomod"
)

// CreateProject is main func to create new project.
Expand Down Expand Up @@ -58,6 +59,11 @@ func CreateProject(projectName string, moduleName string) {
log.Println("create domain hello world")
createdomain.CreateDomain("hello world")

log.Println("run go mod tidy")
if err := gomod.RunGoModTidy(); err != nil {
log.Fatal(fmt.Errorf("err run go mod tidy: %v", err))
}

log.Println("create project finish, go to your project:\n\tcd", projectPath)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package version
import "fmt"

func Version() {
fmt.Println("v0.0.11")
fmt.Println("v0.0.12")
}
20 changes: 20 additions & 0 deletions common/gomod/gomod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package gomod

import (
"fmt"
"os/exec"
)

func RunGoModTidy() error {
cmd := exec.Command("go", "mod", "tidy")
stdout, err := cmd.Output()
if err != nil {
return err
}

if string(stdout) != "" {
fmt.Println(string(stdout))
}

return nil
}

0 comments on commit 6581478

Please sign in to comment.