Skip to content

Commit

Permalink
Merge pull request #8 from fluentdesk/fix/title
Browse files Browse the repository at this point in the history
Always display title on error.
  • Loading branch information
hacksalot committed Oct 26, 2015
2 parents 0d0b8a9 + e34d02f commit 6f578f9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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._ || [];
Expand All @@ -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 ) {
Expand All @@ -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 );

}

0 comments on commit 6f578f9

Please sign in to comment.