Skip to content

Commit

Permalink
Simplified parseArgs function
Browse files Browse the repository at this point in the history
  • Loading branch information
tlaanemaa committed Apr 27, 2019
1 parent bd0c057 commit 0893e76
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/modules/options.js
Expand Up @@ -70,27 +70,28 @@ const usage = commandLineUsage([

// Parse args and handle errors
const parseArgs = () => {
let args;
try {
args = commandLineArgs(optionDefinitions);
const args = commandLineArgs(optionDefinitions);

// Print help if needed
if (args && args.help) {
// eslint-disable-next-line no-console
console.log(usage);
process.exit(0);
}

// Throw error if no operation is provided
if (!args.operation) {
throw new Error('Operation name must be provided!');
}

return args;
} catch (e) {
// eslint-disable-next-line no-console
console.error(e.message, '\nUse the --help option to see docs');
process.exit(1);
throw (e);
}

// Print help if needed
if (args && args.help) {
// eslint-disable-next-line no-console
console.log(usage);
process.exit(0);
}

return args;
};

module.exports = parseArgs();

0 comments on commit 0893e76

Please sign in to comment.