From c8d4a3deb320d8737b0ec01d2511489eb9494eab Mon Sep 17 00:00:00 2001 From: hacksalot Date: Mon, 4 Jan 2016 01:49:35 -0500 Subject: [PATCH] Handle global options. Fix broken --silent flag and set up -o/-opts. --- src/index.js | 26 +++++++++++++++++--------- src/verbs/generate.js | 6 ++++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index f6e603c..f3d3ccf 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ var SPAWNW = require('./core/spawn-watch') , chalk = require('chalk') , PATH = require('path') , HACKMYSTATUS = require('./core/status-codes') - , opts = { } + , _opts = { } , title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***') , StringUtils = require('./utils/string.js') , _ = require('underscore') @@ -40,12 +40,20 @@ function main() { var args = initialize(); + function execVerb( src, dst, opts, log ) { + _opts = opts; + _opts.silent = this.parent.silent; + _opts.opts = this.parent.opts; + FCMD.verbs[ this.name() ].call( null, src, dst, opts, log ); + } + // 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.') - .usage('COMMAND [TO ]'); + .option('-o --opts ', 'Path to a .hackmyrc options file') + .option('-s --silent', 'Run in silent mode'); + //.usage('COMMAND [TO ]'); // Create the NEW command program @@ -55,7 +63,7 @@ function main() { .alias('create') .description('Create resume(s) in FRESH or JSON RESUME format.') .action(function( sources ) { - FCMD.verbs[ this.name() ].call( null, sources, [], this.opts(), logMsg); + execVerb.call( this, sources, [], this.opts(), logMsg); }); // Create the VALIDATE command @@ -64,7 +72,7 @@ function main() { .arguments('') .description('Validate a resume in FRESH or JSON RESUME format.') .action(function(sources) { - FCMD.verbs[ this.name() ].call( null, sources, [], this.opts(), logMsg); + execVerb.call( this, sources, [], this.opts(), logMsg); }); // Create the CONVERT command @@ -74,7 +82,7 @@ function main() { .description('Convert a resume to/from FRESH or JSON RESUME format.') .action(function() { var x = splitSrcDest.call( this ); - FCMD.verbs[ this.name() ].call( null, x.src, x.dst, this.opts(), logMsg); + execVerb.call( this, x.src, x.dst, this.opts(), logMsg); }); // Create the ANALYZE command @@ -83,7 +91,7 @@ function main() { .arguments('') .description('Analyze one or more resumes.') .action(function( sources ) { - FCMD.verbs[ this.name() ].call( null, sources, [], this.opts(), logMsg); + execVerb.call( this, sources, [], this.opts(), logMsg); }); // Create the BUILD command @@ -99,7 +107,7 @@ function main() { .description('Generate resume to multiple formats') .action(function( sources, targets, options ) { var x = splitSrcDest.call( this ); - FCMD.verbs[ this.name() ].call( null, x.src, x.dst, this.opts(), logMsg ); + execVerb.call( this, x.src, x.dst, this.opts(), logMsg); }); // program.on('--help', function(){ @@ -194,5 +202,5 @@ Simple logging placeholder. */ function logMsg( msg ) { msg = msg || ''; - opts.silent || console.log( msg ); + _opts.silent || console.log( msg ); } diff --git a/src/verbs/generate.js b/src/verbs/generate.js index 0131feb..f55f1e9 100644 --- a/src/verbs/generate.js +++ b/src/verbs/generate.js @@ -88,7 +88,8 @@ Implementation of the 'generate' verb for HackMyResume. var numFormats = Object.keys(theme.formats).length; var themeName = theme.name.toUpperCase(); _log( chalk.yellow('Applying ') + chalk.yellow.bold(themeName) + - chalk.yellow(' theme (' + numFormats + ' format' + ( numFormats === 1 ? ')' : 's)') )); + chalk.yellow(' theme (' + numFormats + ' format' + + ( numFormats === 1 ? ')' : 's)') )); // Expand output resumes... var targets = expand( dst, theme ); @@ -135,7 +136,8 @@ Implementation of the 'generate' verb for HackMyResume. } _log( chalk.green('Generating ') + - chalk.green.bold(pad(targInfo.fmt.outFormat.toUpperCase(),4,null,pad.RIGHT)) + + chalk.green.bold( + pad(targInfo.fmt.outFormat.toUpperCase(),4,null,pad.RIGHT)) + chalk.green(' resume') + suffix + chalk.green(': ') + chalk.green.bold( PATH.relative(process.cwd(), f )) );