From d878270bc60df2b7a248db5a00cf88722749dc9b Mon Sep 17 00:00:00 2001 From: hacksalot Date: Fri, 8 Jan 2016 19:22:44 -0500 Subject: [PATCH] Encapsulate CLI interface to ease testing. Strip index.js down to its bare essentials, move primary logic to main.js, and expose the latter via module.exports. This allows tests to execute the same code path(s) HMR runs in production. --- src/index.js | 231 ++----------------------------------------------- src/main.js | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 226 deletions(-) create mode 100644 src/main.js diff --git a/src/index.js b/src/index.js index d8a2ee5..3de0db6 100644 --- a/src/index.js +++ b/src/index.js @@ -10,236 +10,15 @@ Command-line interface (CLI) for HackMyResume. -var SPAWNW = require('./core/spawn-watch') - , HMR = require( './hackmyapi') - , PKG = require('../package.json') - , FS = require('fs') - , EXTEND = require('./utils/extend') - , chalk = require('chalk') - , PATH = require('path') - , HACKMYSTATUS = require('./core/status-codes') - , safeLoadJSON = require('./utils/safe-json-loader') - , _opts = { } - , title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***') - , StringUtils = require('./utils/string.js') - , _ = require('underscore') - , Command = require('commander').Command; - - try { - main(); + + var main = require('./main'); + main( process.argv ); + } catch( ex ) { + require('./core/error-handler').err( ex, true ); -} - - -/** -Kick off the HackMyResume application. -*/ -function main() { - - var args = initialize(); - - // Create the top-level (application) command... - var program = new Command('hackmyresume') - .version(PKG.version) - .description(chalk.yellow.bold('*** HackMyResume ***')) - .option('-o --opts ', 'Path to a .hackmyrc options file') - .option('-s --silent', 'Run in silent mode') - .option('--no-color', 'Disable colors') - .option('--color', 'Enable colors') - .option('-d --debug', 'Enable diagnostics', false); - //.usage('COMMAND [TO ]'); - - // Create the NEW command - program - .command('new') - .arguments('') - .option('-f --format ', 'FRESH or JRS format', 'FRESH') - .alias('create') - .description('Create resume(s) in FRESH or JSON RESUME format.') - .action(function( sources ) { - execVerb.call( this, sources, [], this.opts(), logMsg); - }); - - // Create the VALIDATE command - program - .command('validate') - .arguments('') - .option('-a --assert', 'Treat validation warnings as errors', false) - .description('Validate a resume in FRESH or JSON RESUME format.') - .action(function(sources) { - execVerb.call( this, sources, [], this.opts(), logMsg); - }); - - // Create the CONVERT command - program - .command('convert') - //.arguments('') - .description('Convert a resume to/from FRESH or JSON RESUME format.') - .action(function() { - var x = splitSrcDest.call( this ); - execVerb.call( this, x.src, x.dst, this.opts(), logMsg); - }); - - // Create the ANALYZE command - program - .command('analyze') - .arguments('') - .description('Analyze one or more resumes.') - .action(function( sources ) { - execVerb.call( this, sources, [], this.opts(), logMsg); - }); - - // Create the BUILD command - program - .command('build') - .alias('generate') - //.arguments(' TO [targets]') - //.usage('...') - .option('-t --theme ', 'Theme name or path') - .option('-n --no-prettify', 'Disable HTML prettification', true) - .option('-c --css