From 19c123cbd4f4a7e6fed675b28161b0e01ab804a1 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Tue, 20 Oct 2020 13:47:59 +0200 Subject: [PATCH] Introduce optional command generation Added the possibility to omit the command output file argument and make generation of the command files optional. --- tools/generators/ethereum/contract.go | 46 +++++++++++++++------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/tools/generators/ethereum/contract.go b/tools/generators/ethereum/contract.go index 6c5a5f6..22b2de5 100644 --- a/tools/generators/ethereum/contract.go +++ b/tools/generators/ethereum/contract.go @@ -49,9 +49,11 @@ func main() { flag.Parse() - if flag.NArg() != 3 { + // Two leading arguments (`input.abi` and `contract_output.go`) are required. + // The third argument (`cmd_output.go`) is optional. + if !(flag.NArg() == 2 || flag.NArg() == 3) { panic(fmt.Sprintf( - "Expected `%v [input.abi] [contract_output.go] [cmd_output.go]`, but got [%v].", + "Expected `%v [cmd_output.go]`, but got [%v].", os.Args[0], os.Args, )) @@ -130,27 +132,29 @@ func main() { )) } - commandBuf, err := generateCode( - commandOutputPath, - templates, - "command.go.tmpl", - &contractInfo, - ) - if err != nil { - panic(fmt.Sprintf( - "Failed to generate Go file at [%v]: [%v].", + if len(commandOutputPath) > 0 { + commandBuf, err := generateCode( commandOutputPath, - err, - )) - } + templates, + "command.go.tmpl", + &contractInfo, + ) + if err != nil { + panic(fmt.Sprintf( + "Failed to generate Go file at [%v]: [%v].", + commandOutputPath, + err, + )) + } - // Save the command code to a file. - if err := saveBufferToFile(commandBuf, commandOutputPath); err != nil { - panic(fmt.Sprintf( - "Failed to save Go file at [%v]: [%v].", - commandOutputPath, - err, - )) + // Save the command code to a file. + if err := saveBufferToFile(commandBuf, commandOutputPath); err != nil { + panic(fmt.Sprintf( + "Failed to save Go file at [%v]: [%v].", + commandOutputPath, + err, + )) + } } }