From 9fd96127402634c1ac8ecc20f0e8fdb48b3814fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lker=20G=C3=B6ktu=C4=9F=20=C3=96ZT=C3=9CRK?= Date: Fri, 8 Jan 2021 11:18:36 +0300 Subject: [PATCH 1/2] refactor(cmd): replace cmd.getModule() w/ gomodulepath.ParseAt(). solves a part of #609. --- starport/interface/cli/starport/cmd/build.go | 2 +- starport/interface/cli/starport/cmd/cmd.go | 14 -------------- starport/interface/cli/starport/cmd/relayer.go | 4 ++-- starport/interface/cli/starport/cmd/serve.go | 2 +- starport/pkg/gomodulepath/gomodulepath.go | 4 ++-- starport/services/networkbuilder/blockchain.go | 2 +- starport/services/scaffolder/module.go | 4 ++-- starport/services/scaffolder/type.go | 2 +- 8 files changed, 10 insertions(+), 24 deletions(-) diff --git a/starport/interface/cli/starport/cmd/build.go b/starport/interface/cli/starport/cmd/build.go index a50407dee6..67198dc57d 100644 --- a/starport/interface/cli/starport/cmd/build.go +++ b/starport/interface/cli/starport/cmd/build.go @@ -20,7 +20,7 @@ func NewBuild() *cobra.Command { } func buildHandler(cmd *cobra.Command, args []string) error { - path, err := gomodulepath.Parse(getModule(appPath)) + path, err := gomodulepath.ParseAt(appPath) if err != nil { return err } diff --git a/starport/interface/cli/starport/cmd/cmd.go b/starport/interface/cli/starport/cmd/cmd.go index decd2ea7b5..9ffc62c94e 100644 --- a/starport/interface/cli/starport/cmd/cmd.go +++ b/starport/interface/cli/starport/cmd/cmd.go @@ -2,10 +2,6 @@ package starportcmd import ( "fmt" - "io/ioutil" - "log" - "path/filepath" - "strings" "github.com/fatih/color" "github.com/spf13/cobra" @@ -38,16 +34,6 @@ func New() *cobra.Command { return c } -func getModule(path string) string { - goModFile, err := ioutil.ReadFile(filepath.Join(path, "go.mod")) - if err != nil { - log.Fatal(err) - } - moduleString := strings.Split(string(goModFile), "\n")[0] - modulePath := strings.ReplaceAll(moduleString, "module ", "") - return modulePath -} - func logLevel(cmd *cobra.Command) chain.LogLevel { verbose, _ := cmd.Flags().GetBool("verbose") if verbose { diff --git a/starport/interface/cli/starport/cmd/relayer.go b/starport/interface/cli/starport/cmd/relayer.go index aaab2a7226..e74ddbee1d 100644 --- a/starport/interface/cli/starport/cmd/relayer.go +++ b/starport/interface/cli/starport/cmd/relayer.go @@ -42,7 +42,7 @@ func NewRelayerAdd() *cobra.Command { } func relayerInfoHandler(cmd *cobra.Command, args []string) error { - path, err := gomodulepath.Parse(getModule(appPath)) + path, err := gomodulepath.ParseAt(appPath) if err != nil { return err } @@ -64,7 +64,7 @@ func relayerInfoHandler(cmd *cobra.Command, args []string) error { } func relayerAddHandler(cmd *cobra.Command, args []string) error { - path, err := gomodulepath.Parse(getModule(appPath)) + path, err := gomodulepath.ParseAt(appPath) if err != nil { return err } diff --git a/starport/interface/cli/starport/cmd/serve.go b/starport/interface/cli/starport/cmd/serve.go index 979b8c436c..16cb00c1fd 100644 --- a/starport/interface/cli/starport/cmd/serve.go +++ b/starport/interface/cli/starport/cmd/serve.go @@ -22,7 +22,7 @@ func NewServe() *cobra.Command { } func serveHandler(cmd *cobra.Command, args []string) error { - path, err := gomodulepath.Parse(getModule(appPath)) + path, err := gomodulepath.ParseAt(appPath) if err != nil { return err } diff --git a/starport/pkg/gomodulepath/gomodulepath.go b/starport/pkg/gomodulepath/gomodulepath.go index 136375e2d4..517f31c957 100644 --- a/starport/pkg/gomodulepath/gomodulepath.go +++ b/starport/pkg/gomodulepath/gomodulepath.go @@ -48,8 +48,8 @@ func Parse(rawpath string) (Path, error) { return p, nil } -// ParseFile parses Go module path of an app resides at path. -func ParseFile(path string) (Path, error) { +// ParseAt parses Go module path of an app resides at path. +func ParseAt(path string) (Path, error) { parsed, err := gomodule.ParseAt(path) if err != nil { return Path{}, err diff --git a/starport/services/networkbuilder/blockchain.go b/starport/services/networkbuilder/blockchain.go index 57feb15007..2dbbfddd9a 100644 --- a/starport/services/networkbuilder/blockchain.go +++ b/starport/services/networkbuilder/blockchain.go @@ -45,7 +45,7 @@ func newBlockchain(ctx context.Context, builder *Builder, chainID, appPath, url, func (b *Blockchain) init(ctx context.Context, chainID string, mustNotInitializedBefore bool) error { b.builder.ev.Send(events.New(events.StatusOngoing, "Initializing the blockchain")) - path, err := gomodulepath.ParseFile(b.appPath) + path, err := gomodulepath.ParseAt(b.appPath) if err != nil { return err } diff --git a/starport/services/scaffolder/module.go b/starport/services/scaffolder/module.go index cc8902e07e..93761227ac 100644 --- a/starport/services/scaffolder/module.go +++ b/starport/services/scaffolder/module.go @@ -39,7 +39,7 @@ func (s *Scaffolder) CreateModule(moduleName string) error { if ok { return fmt.Errorf("the module %v already exists", moduleName) } - path, err := gomodulepath.ParseFile(s.path) + path, err := gomodulepath.ParseAt(s.path) if err != nil { return err } @@ -96,7 +96,7 @@ func (s *Scaffolder) ImportModule(name string) error { return err } - path, err := gomodulepath.ParseFile(s.path) + path, err := gomodulepath.ParseAt(s.path) if err != nil { return err } diff --git a/starport/services/scaffolder/type.go b/starport/services/scaffolder/type.go index bc80d364ef..701b7d41d1 100644 --- a/starport/services/scaffolder/type.go +++ b/starport/services/scaffolder/type.go @@ -28,7 +28,7 @@ func (s *Scaffolder) AddType(moduleName string, stype string, fields ...string) if err != nil { return err } - path, err := gomodulepath.ParseFile(s.path) + path, err := gomodulepath.ParseAt(s.path) if err != nil { return err } From 5ec9dfd1223d05fb013fa4af804916301c1f2baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lker=20G=C3=B6ktu=C4=9F=20=C3=96ZT=C3=9CRK?= Date: Fri, 8 Jan 2021 13:22:41 +0300 Subject: [PATCH 2/2] fix after merge --- starport/services/networkbuilder/networkbuilder.go | 2 +- starport/services/networkbuilder/simulation.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/starport/services/networkbuilder/networkbuilder.go b/starport/services/networkbuilder/networkbuilder.go index 70e56d5b08..c1fd10b749 100644 --- a/starport/services/networkbuilder/networkbuilder.go +++ b/starport/services/networkbuilder/networkbuilder.go @@ -299,7 +299,7 @@ func (b *Builder) StartChain(ctx context.Context, chainID string, flags []string } appPath := filepath.Join(sourcePath, chainID) - path, err := gomodulepath.ParseFile(appPath) + path, err := gomodulepath.ParseAt(appPath) if err != nil { return err } diff --git a/starport/services/networkbuilder/simulation.go b/starport/services/networkbuilder/simulation.go index e2a06dbd06..3bf2ffd4de 100644 --- a/starport/services/networkbuilder/simulation.go +++ b/starport/services/networkbuilder/simulation.go @@ -47,7 +47,7 @@ func (b *Builder) VerifyProposals(ctx context.Context, chainID string, proposals defer os.RemoveAll(tmpHome) appPath := filepath.Join(sourcePath, chainID) - path, err := gomodulepath.ParseFile(appPath) + path, err := gomodulepath.ParseAt(appPath) if err != nil { return false, err }