2015-09-01 06:05:47 +01:00
|
|
|
#! /usr/bin/env node
|
|
|
|
|
|
|
|
/**
|
2015-11-19 06:57:15 +00:00
|
|
|
Command-line interface (CLI) for FluentCV:CLI.
|
|
|
|
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
|
2015-09-01 06:05:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
var ARGS = require( 'minimist' )
|
2015-10-07 14:29:41 +01:00
|
|
|
, FCMD = require( './fluentcmd')
|
2015-10-26 17:17:58 +00:00
|
|
|
, PKG = require('../package.json')
|
|
|
|
, opts = { };
|
|
|
|
|
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
|
|
|
|
try {
|
2015-10-25 07:04:51 +00:00
|
|
|
main();
|
|
|
|
}
|
|
|
|
catch( ex ) {
|
|
|
|
handleError( ex );
|
|
|
|
}
|
|
|
|
|
2015-10-26 17:17:58 +00:00
|
|
|
|
|
|
|
|
2015-10-25 07:04:51 +00:00
|
|
|
function main() {
|
2015-10-26 12:01:01 +00:00
|
|
|
|
2015-11-19 14:46:02 +00:00
|
|
|
// Setup
|
2015-10-27 07:54:50 +00:00
|
|
|
var title = '*** FluentCV v' + PKG.version + ' ***';
|
2015-11-19 14:46:02 +00:00
|
|
|
if( process.argv.length <= 2 ) { logMsg(title); throw { fluenterror: 4 }; }
|
|
|
|
var a = ARGS( process.argv.slice(2) );
|
|
|
|
opts = getOpts( a );
|
2015-10-26 17:17:58 +00:00
|
|
|
logMsg( title );
|
2015-10-25 07:04:51 +00:00
|
|
|
|
2015-11-19 14:46:02 +00:00
|
|
|
// Get the action to be performed
|
|
|
|
var verb = a._[0].toLowerCase().trim();
|
|
|
|
if( !FCMD.verbs[ verb ] ) {
|
|
|
|
throw 'Invalid command: "' + verb + '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preload our params array
|
|
|
|
var dst = (a.o && ((typeof a.o === 'string' && [ a.o ]) || a.o)) || [];
|
2015-10-25 07:04:51 +00:00
|
|
|
dst = (dst === true) ? [] : dst; // Handle -o with missing output file
|
2015-11-19 14:46:02 +00:00
|
|
|
var parms = [ a._.slice(1) || [], dst, opts, logMsg ];
|
|
|
|
|
|
|
|
// Invoke the action
|
|
|
|
FCMD.verbs[ verb ].apply( null, parms );
|
2015-10-25 07:04:51 +00:00
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
}
|
2015-10-07 14:29:41 +01:00
|
|
|
|
2015-10-26 12:01:01 +00:00
|
|
|
function logMsg( msg ) {
|
|
|
|
opts.silent || console.log( msg );
|
|
|
|
}
|
|
|
|
|
2015-10-25 07:04:51 +00:00
|
|
|
function getOpts( args ) {
|
|
|
|
var noPretty = args['nopretty'] || args.n;
|
|
|
|
noPretty = noPretty && (noPretty === true || noPretty === 'true');
|
|
|
|
return {
|
|
|
|
theme: args.t || 'modern',
|
2015-10-26 12:01:01 +00:00
|
|
|
prettify: !noPretty,
|
|
|
|
silent: args.s || args.silent
|
2015-10-25 07:04:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleError( ex ) {
|
2015-10-26 17:17:58 +00:00
|
|
|
var msg = '', exitCode;
|
2015-10-07 14:29:41 +01:00
|
|
|
if( ex.fluenterror ){
|
2015-10-11 02:39:32 +01:00
|
|
|
switch( ex.fluenterror ) { // TODO: Remove magic numbers
|
2015-10-07 14:29:41 +01:00
|
|
|
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;
|
2015-11-19 14:46:02 +00:00
|
|
|
case 4: msg = "Please specify a valid command (GENERATE, VALIDATE, or CONVERT)."
|
2015-10-07 14:29:41 +01:00
|
|
|
};
|
2015-10-26 17:17:58 +00:00
|
|
|
exitCode = ex.fluenterror;
|
2015-10-07 14:29:41 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
msg = ex.toString();
|
2015-10-26 17:17:58 +00:00
|
|
|
exitCode = 4;
|
2015-10-07 14:29:41 +01:00
|
|
|
}
|
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
var idx = msg.indexOf('Error: ');
|
|
|
|
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
|
|
|
|
console.log( 'ERROR: ' + trimmed.toString() );
|
2015-10-26 17:17:58 +00:00
|
|
|
process.exit( exitCode );
|
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
}
|