From c166c8da0ab9229e4cf3492122f18e59b5ba4066 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Wed, 13 Nov 2019 11:26:55 +0800 Subject: [PATCH] cmd/abigen: address comments --- cmd/abigen/main.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index 0efd3f880c..659cf1b4c5 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "os" + "regexp" "strings" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -240,24 +241,16 @@ func abigen(c *cli.Context) error { } // Extract all aliases from the flags if c.GlobalIsSet(aliasFlag.Name) { - v := strings.Split(c.GlobalString(aliasFlag.Name), ",") - for _, alias := range v { - // We support multi-versions for aliasing - // e.g. - // foo=bar - // foo:bar - index := strings.Index(alias, ":") - if index == -1 { - index = strings.Index(alias, "=") - } - // Filter out invalid aliasing - if index == -1 || index == 0 || index == len(alias)-1 { - continue - } - aliases[alias[:index]] = alias[index+1:] // Add to the aliasing map + // We support multi-versions for aliasing + // e.g. + // foo=bar,foo2=bar2 + // foo:bar,foo2:bar2 + re := regexp.MustCompile(`(?:(\w+)[:=](\w+))`) + submatches := re.FindAllStringSubmatch(c.GlobalString(aliasFlag.Name), -1) + for _, match := range submatches { + aliases[match[1]] = match[2] } } - // Generate the contract binding code, err := bind.Bind(types, abis, bins, sigs, c.GlobalString(pkgFlag.Name), lang, libs, aliases) if err != nil {