Skip to content

Commit

Permalink
Remove flag --pkgPath in favour of gno.mod file
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Nov 27, 2023
1 parent b203b8d commit c3acd88
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tm2/pkg/crypto/keys/client/addpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"context"
"flag"
"fmt"
"path/filepath"

"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/pkg/gnomod"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
Expand All @@ -19,7 +21,6 @@ import (
type addPkgCfg struct {
rootCfg *makeTxCfg

pkgPath string
pkgDir string
deposit string
}
Expand All @@ -43,13 +44,6 @@ func newAddPkgCmd(rootCfg *makeTxCfg, io commands.IO) *commands.Command {
}

func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.pkgPath,
"pkgpath",
"",
"package path (required)",
)

fs.StringVar(
&c.pkgDir,
"pkgdir",
Expand All @@ -66,9 +60,6 @@ func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) {
}

func execAddPkg(cfg *addPkgCfg, args []string, io commands.IO) error {
if cfg.pkgPath == "" {
return errors.New("pkgpath not specified")
}
if cfg.pkgDir == "" {
return errors.New("pkgdir not specified")
}
Expand Down Expand Up @@ -96,10 +87,17 @@ func execAddPkg(cfg *addPkgCfg, args []string, io commands.IO) error {
panic(err)
}

// read and parse gno.mod
gm, err := gnomod.ParseGnoMod(filepath.Join(cfg.pkgDir, "gno.mod"))
if err != nil {
panic(err)

Check warning on line 93 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L91-L93

Added lines #L91 - L93 were not covered by tests
}

// open files in directory as MemPackage.
memPkg := gno.ReadMemPackage(cfg.pkgDir, cfg.pkgPath)
pkgPath := gm.Module.Mod.Path
memPkg := gno.ReadMemPackage(cfg.pkgDir, pkgPath)

Check warning on line 98 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L97-L98

Added lines #L97 - L98 were not covered by tests
if memPkg.IsEmpty() {
panic(fmt.Sprintf("found an empty package %q", cfg.pkgPath))
panic(fmt.Sprintf("found an empty package %q", pkgPath))

Check warning on line 100 in tm2/pkg/crypto/keys/client/addpkg.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/addpkg.go#L100

Added line #L100 was not covered by tests
}

// precompile and validate syntax
Expand Down

0 comments on commit c3acd88

Please sign in to comment.