Better messaging for unknown options

This commit is contained in:
Will Boyd
2020-01-21 16:52:37 -05:00
parent fc37978d90
commit cf39eda9e7
2 changed files with 26 additions and 2 deletions
+25 -1
View File
@@ -3,6 +3,7 @@ const commander = require('commander');
const fs = require('fs');
const inquirer = require('inquirer');
const path = require('path');
const process = require('process');
const package = require('../package.json');
@@ -137,7 +138,30 @@ function parseCommandLine(argv) {
commander.option(flag, input.description, coerce, input.default);
});
return commander.parse(argv);
commander.exitOverride();
let program;
try {
program = commander.parse(argv);
} catch (ex) {
switch (ex.code) {
case 'commander.version':
case 'commander.helpDisplayed':
// not really an error, but should quit here
process.exit();
break;
case 'commander.unknownOption':
// provide more helpful information for unknown options
console.log('\nIt could be a typo or the option might be obsolete. For help:');
console.log('- Run the script again with no options and let the wizard set them for you.');
console.log('- Or check documentation at https://github.com/lonekorean/wordpress-export-to-markdown.');
process.exit();
break;
default:
throw ex;
}
}
return program;
}
function coerceBoolean(value) {
+1 -1
View File
@@ -20,7 +20,7 @@ async function processPayloadsPromise(payloads, loadFunc, config) {
console.log(chalk.green('[OK]') + ' ' + payload.name);
resolve();
} catch (ex) {
console.error(chalk.red('[FAILED]') + ' ' + payload.name + ' ' + chalk.red('(' + ex.toString() + ')'));
console.log(chalk.red('[FAILED]') + ' ' + payload.name + ' ' + chalk.red('(' + ex.toString() + ')'));
reject();
}
}, payload.delay);