diff --git a/packages/truffle-core/lib/command.js b/packages/truffle-core/lib/command.js index 9fde2b76890..60074f8481f 100644 --- a/packages/truffle-core/lib/command.js +++ b/packages/truffle-core/lib/command.js @@ -100,9 +100,41 @@ class Command { } }); - const newOptions = Object.assign({}, clone, argv); - + //Check unsupported command line flag according to the option list in help try { + const inputOptions = inputStrings + .map(string => { + return string.startsWith("--") ? string : null; + }) + .filter(item => { + return item != null; + }); + + const validOptions = result.command.help.options + .map(item => { + let opt = item.option.split(" ")[0]; + return opt.startsWith("--") ? opt : null; + }) + .filter(item => { + return item != null; + }); + + let invalidOptions = inputOptions.filter( + opt => !validOptions.includes(opt) + ); + + if (invalidOptions.length > 0) { + if (options.logger) { + const log = options.logger.log || options.logger.debug; + log( + "> Warning: possible unsupported (undocumented in help) command line option: " + + invalidOptions + ); + } + } + + const newOptions = Object.assign({}, clone, argv); + result.command.run(newOptions, callback); analytics.send({ command: result.name ? result.name : "other", diff --git a/packages/truffle-core/lib/commands/obtain.js b/packages/truffle-core/lib/commands/obtain.js index 085ebbbdb0f..28895f3e3d9 100644 --- a/packages/truffle-core/lib/commands/obtain.js +++ b/packages/truffle-core/lib/commands/obtain.js @@ -2,14 +2,11 @@ module.exports = { command: "obtain", description: "Fetch and cache a specified compiler", help: { - usage: "truffle obtain <-- >", + usage: "truffle obtain [--solc ]", options: [ { - option: "<-- >", - description: - `Download and cache a version of the specified compiler.\n` + - ` compiler_name must be one of the following: ` + - `'solc'.(required)` + option: "--solc ", + description: `Download and cache a version of the solc compiler. (required)` } ] }, diff --git a/packages/truffle-core/test/commands.js b/packages/truffle-core/test/commands.js index bc649bddc20..02c688c0bb4 100644 --- a/packages/truffle-core/test/commands.js +++ b/packages/truffle-core/test/commands.js @@ -37,4 +37,37 @@ describe("Commander", function() { var actualCommand = commander.getCommand("console").command; assert.equal(actualCommand, commands.console); }); + + it("will warn and display error for unsupported flags in commands", function() { + var actualCommand = commander.getCommand("mig").command; + assert.equal(actualCommand, commands.migrate); + + const originalLog = console.log || console.debug; + let warning = ""; + console.log = function(msg) { + console.log = originalLog; + warning = msg; + }; + + commander.run( + [ + "migrate", + "--network", + "localhost", + "--unsupportedflag", + "invalidoption", + "--unsupportedflag2", + "invalidflag2" + ], + { noAliases: true, logger: console }, + function() { + //ignore. not part of test + } + ); + + assert.equal( + warning, + "> Warning: possible unsupported (undocumented in help) command line option: --unsupportedflag,--unsupportedflag2" + ); + }); });