Skip to content

Commit

Permalink
Merge pull request #53 from keep-network/optional-commands
Browse files Browse the repository at this point in the history
Introduce optional command generation

Added the possibility to omit the command output file argument
and make the generation of the command files optional.
  • Loading branch information
pdyraga authored Oct 22, 2020
2 parents 397dbfe + 19c123c commit ea88903
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions tools/generators/ethereum/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <input.abi> <contract_output.go> [cmd_output.go]`, but got [%v].",
os.Args[0],
os.Args,
))
Expand Down Expand Up @@ -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,
))
}
}
}

Expand Down

0 comments on commit ea88903

Please sign in to comment.