Skip to content

Commit 0287e1a

Browse files
authoredMay 26, 2022
cmd/abigen: accept combined-json via stdin (ethereum#24960)

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
 

‎cmd/abigen/main.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
}
5656
jsonFlag = cli.StringFlag{
5757
Name: "combined-json",
58-
Usage: "Path to the combined-json file generated by compiler",
58+
Usage: "Path to the combined-json file generated by compiler, - for STDIN",
5959
}
6060
excFlag = cli.StringFlag{
6161
Name: "exc",
@@ -165,9 +165,18 @@ func abigen(c *cli.Context) error {
165165
var contracts map[string]*compiler.Contract
166166

167167
if c.GlobalIsSet(jsonFlag.Name) {
168-
jsonOutput, err := os.ReadFile(c.GlobalString(jsonFlag.Name))
168+
var (
169+
input = c.GlobalString(jsonFlag.Name)
170+
jsonOutput []byte
171+
err error
172+
)
173+
if input == "-" {
174+
jsonOutput, err = io.ReadAll(os.Stdin)
175+
} else {
176+
jsonOutput, err = os.ReadFile(input)
177+
}
169178
if err != nil {
170-
utils.Fatalf("Failed to read combined-json from compiler: %v", err)
179+
utils.Fatalf("Failed to read combined-json: %v", err)
171180
}
172181
contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "")
173182
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.