/** Definition of the `main` function. @module cli/main @license MIT. See LICENSE.md for details. */ (function(){ var HMR = require( '../hackmyapi') , PKG = require('../../package.json') , FS = require('fs') , EXTEND = require('extend') , chalk = require('chalk') , PATH = require('path') , HMSTATUS = require('../core/status-codes') , HME = require('../core/event-codes') , safeLoadJSON = require('../utils/safe-json-loader') , StringUtils = require('../utils/string.js') , _ = require('underscore') , OUTPUT = require('./out') , PAD = require('string-padding') , Command = require('commander').Command; var _opts = { }; var _title = chalk.white.bold('\n*** HackMyResume v' +PKG.version+ ' ***'); var _out = new OUTPUT( _opts ); /** A callable implementation of the HackMyResume CLI. Encapsulates the command line interface as a single method accepting a parameter array. @alias module:cli/main.main @param rawArgs {Array} An array of command-line parameters. Will either be process.argv (in production) or custom parameters (in test). */ var main = module.exports = function( rawArgs ) { var initInfo = initialize( rawArgs ); var args = initInfo.args; // Create the top-level (application) command... var program = new Command('hackmyresume') .version(PKG.version) .description(chalk.yellow.bold('*** HackMyResume ***')) .option('-s --silent', 'Run in silent mode') .option('--no-color', 'Disable colors') .option('--color', 'Enable colors') .option('-d --debug', 'Enable diagnostics', false) .option('-a --assert', 'Treat warnings as errors', false) .option('-v --version', 'Show the version') .allowUnknownOption(); program.jsonArgs = initInfo.options; // 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 ) { execute.call( this, sources, [], this.opts(), logMsg); }); // Create the VALIDATE command program .command('validate') .arguments('') .description('Validate a resume in FRESH or JSON RESUME format.') .action(function(sources) { execute.call( this, sources, [], this.opts(), logMsg); }); // Create the CONVERT command program .command('convert') .description('Convert a resume to/from FRESH or JSON RESUME format.') .action(function() { var x = splitSrcDest.call( this ); execute.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 ) { execute.call( this, sources, [], this.opts(), logMsg); }); // Create the PEEK command program .command('peek') .arguments('') .description('Peek at a resume field or section') .action(function( sources, sectionOrField ) { var dst = (sources && sources.length > 1) ? [sources.pop()] : []; execute.call( this, sources, dst, this.opts(), logMsg); }); // Create the BUILD command program .command('build') .alias('generate') .option('-t --theme ', 'Theme name or path') .option('-n --no-prettify', 'Disable HTML prettification', true) .option('-c --css