From e34d02facb6b8093089779ee86c3945276815533 Mon Sep 17 00:00:00 2001 From: devlinjd Date: Mon, 26 Oct 2015 13:17:58 -0400 Subject: [PATCH] Always display title on error. --- src/index.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 7d94fb4..f7ad8cd 100644 --- a/src/index.js +++ b/src/index.js @@ -7,23 +7,28 @@ Command-line interface (CLI) for FluentCMD via Node.js. var ARGS = require( 'minimist' ) , FCMD = require( './fluentcmd') - , PKG = require('../package.json'); + , PKG = require('../package.json') + , opts = { }; + + try { - var opts = { }; main(); } catch( ex ) { handleError( ex ); } + + function main() { // Setup. - if( process.argv.length <= 2 ) { throw { fluenterror: 3 }; } + var title = '*** FluentCMD v' + PKG.version + ' ***'; + if( process.argv.length <= 2 ) { logMsg(title); throw { fluenterror: 3 }; } var args = ARGS( process.argv.slice(2) ); opts = getOpts( args ); - logMsg( '*** FluentCMD v' + PKG.version + ' ***' ); + logMsg( title ); // Convert arguments to source files, target files, options var src = args._ || []; @@ -32,7 +37,8 @@ function main() { // Generate! FCMD.generate( src, dst, opts, logMsg ); - process.platform !== 'win32' && console.log('\n'); + + process.exit(0); } function logMsg( msg ) { @@ -50,19 +56,23 @@ function getOpts( args ) { } function handleError( ex ) { - var msg = ''; + var msg = '', exitCode; if( ex.fluenterror ){ switch( ex.fluenterror ) { // TODO: Remove magic numbers case 1: msg = "The specified theme couldn't be found: " + ex.data; break; case 2: msg = "Couldn't copy CSS file to destination folder"; break; case 3: msg = "Please specify a valid JSON resume file."; break; }; + exitCode = ex.fluenterror; } else { msg = ex.toString(); + exitCode = 4; } var idx = msg.indexOf('Error: '); var trimmed = idx === -1 ? msg : msg.substring( idx + 7 ); console.log( 'ERROR: ' + trimmed.toString() ); + process.exit( exitCode ); + }