###* Definition of the `main` function. @module cli/main @license MIT. See LICENSE.md for details. ### HMR = require '../index' 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 M2C = require '../utils/md2chalk' printf = require 'printf' _opts = { } _title = chalk.white.bold('\n*** HackMyResume v' +PKG.version+ ' ***') _out = new OUTPUT( _opts ) _err = require('./error') _exitCallback = null ### 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). ### main = module.exports = ( rawArgs, exitCallback ) -> initInfo = initialize( rawArgs, exitCallback ) if initInfo is null return args = initInfo.args # Create the top-level (application) command... 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 (( sources ) -> execute.call( this, sources, [], this.opts(), logMsg) return ) # Create the VALIDATE command program .command('validate') .arguments('') .description('Validate a resume in FRESH or JSON RESUME format.') .action((sources) -> execute.call( this, sources, [], this.opts(), logMsg) return ) # Create the CONVERT command program .command('convert') .description('Convert a resume to/from FRESH or JSON RESUME format.') .option('-f --format ', 'FRESH or JRS format and optional version', undefined) .action(-> x = splitSrcDest.call( this ); execute.call( this, x.src, x.dst, this.opts(), logMsg) return ) # Create the ANALYZE command program .command('analyze') .arguments('') .option('--private', 'Include resume fields marked as private', false) .description('Analyze one or more resumes.') .action(( sources ) -> execute.call( this, sources, [], this.opts(), logMsg) return ) # Create the PEEK command program .command('peek') .arguments('') .description('Peek at a resume field or section') .action(( sources, sectionOrField ) -> dst = if (sources && sources.length > 1) then [sources.pop()] else [] execute.call( this, sources, dst, this.opts(), logMsg) return ) # 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