Skip to content

Commit

Permalink
feat(cmd/gno): pkgaddr subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Norman <[email protected]>
  • Loading branch information
n0izn0iz committed Dec 28, 2024
1 parent ea32315 commit fbc608e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions gnovm/cmd/gno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func newGnocliCmd(io commands.IO) *commands.Command {
newEnvCmd(io),
newBugCmd(io),
newFmtCmd(io),
newPkgAddrCmd(io),
// graph
// vendor -- download deps from the chain in vendor/
// list -- list packages
Expand Down
33 changes: 33 additions & 0 deletions gnovm/cmd/gno/pkgaddr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"context"
"fmt"

"github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/tm2/pkg/commands"
)

func newPkgAddrCmd(io commands.IO) *commands.Command {
return commands.NewCommand(
commands.Metadata{
Name: "pkgaddr",
ShortUsage: "pkgaddr <pkgpath>",
ShortHelp: "`pkgaddr` converts a package path to a package address",
},
nil,
func(_ context.Context, args []string) error {
return execPkgAddr(args, io)
},
)
}

func execPkgAddr(args []string, io commands.IO) error {
if len(args) != 1 {
return fmt.Errorf("expected 1 arg, got %d", len(args))
}

io.Println(gnolang.DerivePkgAddr(args[0]))

return nil
}

0 comments on commit fbc608e

Please sign in to comment.