abigen support for --type flag with piped data

`abigen` fails to support the `--type` flag when data is piped to it.
Ethereum Issue: #17647

This change is to fix the command line processing to support
a piped ABI to `abigen` and use the `--type` flag.
This commit is contained in:
Philip Schlump 2018-09-11 20:17:58 -06:00
parent 2d98099c25
commit 6cd053bcfe

View file

@ -75,7 +75,7 @@ func main() {
bins []string
types []string
)
if *solFlag != "" || *abiFlag == "-" {
if *solFlag != "" || (*abiFlag == "-" && *pkgFlag == "") {
// Generate the list of types to exclude from binding
exclude := make(map[string]bool)
for _, kind := range strings.Split(*excFlag, ",") {
@ -111,11 +111,21 @@ func main() {
}
} else {
// Otherwise load up the ABI, optional bytecode and type name from the parameters
abi, err := ioutil.ReadFile(*abiFlag)
var abi []byte
var err error
if *abiFlag == "-" {
abi, err = ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Printf("Failed to read input ABI from stdin: %v\n", err)
os.Exit(-1)
}
} else {
abi, err = ioutil.ReadFile(*abiFlag)
if err != nil {
fmt.Printf("Failed to read input ABI: %v\n", err)
os.Exit(-1)
}
}
abis = append(abis, string(abi))
bin := []byte{}
@ -156,5 +166,10 @@ func contractsFromStdin() (map[string]*compiler.Contract, error) {
return nil, err
}
return compiler.ParseCombinedJSON(bytes, "", "", "", "")
code, err := compiler.ParseCombinedJSON(bytes, "", "", "", "")
if err != nil {
fmt.Printf("Error from parse: %s\n", err)
return nil, err
}
return code, nil
}