From 80f85183ee5cacddbef81ca83b46997de89e3798 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 26 May 2022 09:26:37 +0200 Subject: [PATCH] cmd/abigen: accept combined-json via stdin (#24960) --- cmd/abigen/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index 588de30bf51f5..0aef7d8676039 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -56,7 +56,7 @@ var ( } jsonFlag = &cli.StringFlag{ Name: "combined-json", - Usage: "Path to the combined-json file generated by compiler", + Usage: "Path to the combined-json file generated by compiler, - for STDIN", } excFlag = &cli.StringFlag{ Name: "exc", @@ -155,9 +155,18 @@ func abigen(c *cli.Context) error { var contracts map[string]*compiler.Contract if c.IsSet(jsonFlag.Name) { - jsonOutput, err := os.ReadFile(c.String(jsonFlag.Name)) + var ( + input = c.String(jsonFlag.Name) + jsonOutput []byte + err error + ) + if input == "-" { + jsonOutput, err = io.ReadAll(os.Stdin) + } else { + jsonOutput, err = os.ReadFile(input) + } if err != nil { - utils.Fatalf("Failed to read combined-json from compiler: %v", err) + utils.Fatalf("Failed to read combined-json: %v", err) } contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "") if err != nil {