OpenZeppelin / openzeppelin-sdk

OpenZeppelin SDK repository for CLI and upgrades.js. No longer actively developed.
MIT License
431 stars 200 forks source link

Review argument parsing in the CLI in non-interactive mode #981

Open gskapka opened 5 years ago

gskapka commented 5 years ago

Error in argument parsing in the CLI: string args containing dashes cause error. For a given Contract with an initializer argument of type string:

zos create Contract --args string-withDash

or

zos create Contract --args 'string-withDash'

...both fail with:

[Error] Error: Error parsing arguments: SyntaxError: Unexpected token s in JSON at position 1
    at parseArgs (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/utils/input.js:39:15)
    at Object.parseInit (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/utils/input.js:50:20)
    at Object.<anonymous> (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/prompts/init-params.js:23:48)
    at Generator.next (<anonymous>)
    at /home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/prompts/init-params.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/prompts/init-params.js:3:12)
    at Object.promptForMethodParams [as default] (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/prompts/init-params.js:21:12)
    at Command.<anonymous> (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/commands/create.js:51:55)
    at Generator.next (<anonymous>)
    at fulfilled (/home/user/.nvm/versions/node/v10.15.0/lib/node_modules/zos/lib/commands/create.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
spalladino commented 5 years ago

Thanks for the report @gskapka!

To fix this, we should decouple the method and args parsing in input#parseMethodParams. Instead of trying to parse both together, we should:

This should allow us to delete input#parseArgs once and for all.