diff --git a/tm2/pkg/crypto/keys/client/addpkg.go b/tm2/pkg/crypto/keys/client/addpkg.go index 5bbd3f08ad04..14766b7d443a 100644 --- a/tm2/pkg/crypto/keys/client/addpkg.go +++ b/tm2/pkg/crypto/keys/client/addpkg.go @@ -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" @@ -19,7 +21,6 @@ import ( type addPkgCfg struct { rootCfg *makeTxCfg - pkgPath string pkgDir string deposit string } @@ -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", @@ -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") } @@ -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) + } + // open files in directory as MemPackage. - memPkg := gno.ReadMemPackage(cfg.pkgDir, cfg.pkgPath) + pkgPath := gm.Module.Mod.Path + memPkg := gno.ReadMemPackage(cfg.pkgDir, pkgPath) if memPkg.IsEmpty() { - panic(fmt.Sprintf("found an empty package %q", cfg.pkgPath)) + panic(fmt.Sprintf("found an empty package %q", pkgPath)) } // precompile and validate syntax