Skip to content

Commit

Permalink
Warn/error about unsupported flags trufflesuite#468
Browse files Browse the repository at this point in the history
Warn/error about unsupported flags trufflesuite#468
  • Loading branch information
skywing committed Jun 20, 2019
1 parent 3ea1fef commit 650d2db
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/truffle-core/lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ class Command {
}
});

//Check unsupported command line flag according to the option list in help
try {
const inputOptions = [];
inputStrings.map(i => {
if (i.startsWith("--")) {
inputOptions.push(i);
}
});

const validOptions = [];
result.command.help.options.map(item => {
let opt = item.option.split(" ")[0];
if (opt.startsWith("--")) validOptions.push(opt);
});

let notValidOptions = inputOptions.filter(
opt => !validOptions.includes(opt)
);

if (notValidOptions.length > 0)
return callback(
new TaskError(
"Unsupported (Undocumented) command line option: " + notValidOptions
)
);
} catch (err) {
callback(err);
}

const newOptions = Object.assign({}, clone, argv);

try {
Expand Down
21 changes: 21 additions & 0 deletions packages/truffle-core/test/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,25 @@ describe("Commander", function() {
var actualCommand = commander.getCommand("console").command;
assert.equal(actualCommand, commands.console);
});

it("will stop and display error for unsupported flags in commands", function() {
var actualCommand = commander.getCommand("mig").command;
assert.equal(actualCommand, commands.migrate);
commander.run(
[
"migrate",
"--network",
"localhost",
"--unsupportedflag",
"invalidoption"
],
{ noAliases: true },
function(err) {
assert.equal(
err.message.split(":")[0],
"Unsupported (Undocumented) command line option"
);
}
);
});
});

0 comments on commit 650d2db

Please sign in to comment.