1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 00:10:15 +00:00

Reconnect process exit codes.

This commit is contained in:
hacksalot 2016-01-18 20:06:45 -05:00
parent 23cd52885b
commit 2f628f8564
9 changed files with 46 additions and 25 deletions

View File

@ -16,7 +16,7 @@ Definition of the `main` function.
, EXTEND = require('extend')
, chalk = require('chalk')
, PATH = require('path')
, HACKMYSTATUS = require('../core/status-codes')
, HMSTATUS = require('../core/status-codes')
, HME = require('../core/event-codes')
, safeLoadJSON = require('../utils/safe-json-loader')
, StringUtils = require('../utils/string.js')
@ -150,14 +150,15 @@ Definition of the `main` function.
// Handle invalid verbs here (a bit easier here than in commander.js)...
if( o.verb && !HMR.verbs[ o.verb ] && !HMR.alias[ o.verb ] ) {
throw { fluenterror: HACKMYSTATUS.invalidCommand, shouldExit: true,
throw { fluenterror: HMSTATUS.invalidCommand, quit: true,
attempted: o.orgVerb };
}
// Override the .missingArgument behavior
Command.prototype.missingArgument = function(name) {
if( this.name() !== 'new' )
throw { fluenterror: HACKMYSTATUS.resumeNotFound };
if( this.name() !== 'new' ) {
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
}
};
// Override the .helpInformation behavior
@ -243,7 +244,8 @@ Definition of the `main` function.
hand.err.apply( hand, arguments );
});
v.invoke.call( v, src, dst, _opts, log );
if( v.errorCode )
process.exit(v.errorCode);
}
@ -293,7 +295,7 @@ Definition of the `main` function.
var params = this.parent.args.filter(function(j) { return String.is(j); });
if( params.length === 0 )
throw { fluenterror: HACKMYSTATUS.resumeNotFound };
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
// Find the TO keyword, if any
var splitAt = _.findIndex( params, function(p) {

View File

@ -42,7 +42,7 @@ Implementation of the 'analyze' verb for HackMyResume.
*/
function analyze( sources, dst, opts ) {
if( !sources || !sources.length )
throw { fluenterror: HMSTATUS.resumeNotFound };
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
var nlzrs = _loadInspectors();
@ -50,7 +50,10 @@ Implementation of the 'analyze' verb for HackMyResume.
var result = ResumeFactory.loadOne( src, {
format: 'FRESH', objectify: true
}, this);
result.fluenterror || _analyze.call(this, result, nlzrs, opts );
if( result.fluenterror )
this.setError( result.fluenterror, result );
else
_analyze.call(this, result, nlzrs, opts );
}, this);
}

View File

@ -62,7 +62,9 @@ Implementation of the 'build' verb for HackMyResume.
*/
function build( src, dst, opts ) {
if( !src || !src.length ) { this.err( HMSTATUS.resumeNotFound ); }
if( !src || !src.length ) {
this.err( HMSTATUS.resumeNotFound, { quit: true } );
}
prep( src, dst, opts );

View File

@ -40,20 +40,20 @@ Implementation of the 'convert' verb for HackMyResume.
function convert( srcs, dst, opts ) {
// Housekeeping
if( !srcs || !srcs.length ) { throw { fluenterror: 6 }; }
if( !srcs || !srcs.length ) { throw { fluenterror: 6, quit: true }; }
if( !dst || !dst.length ) {
if( srcs.length === 1 ) {
throw { fluenterror: HMSTATUS.inputOutputParity };
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
}
else if( srcs.length === 2 ) {
dst = dst || []; dst.push( srcs.pop() );
}
else {
throw { fluenterror: HMSTATUS.inputOutputParity };
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
}
}
if(srcs && dst && srcs.length && dst.length && srcs.length !== dst.length){
throw { fluenterror: HMSTATUS.inputOutputParity };
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
}
// Load source resumes

View File

@ -41,7 +41,8 @@ Implementation of the 'create' verb for HackMyResume.
*/
function create( src, dst, opts ) {
if(!src || !src.length) throw {fluenterror: HMSTATUS.createNameMissing};
if( !src || !src.length )
throw { fluenterror: HMSTATUS.createNameMissing, quit: true };
_.each( src, function( t ) {
var safeFmt = opts.format.toUpperCase();

View File

@ -67,13 +67,12 @@ Implementation of the 'peek' verb for HackMyResume.
// safeLoadJSON can only return a READ error or a PARSE error
if( obj.ex ) {
if( obj.ex.operation === 'parse' )
this.err( HMSTATUS.parseError, obj.ex );
else {
var errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
if( errCode === HMSTATUS.readError )
obj.ex.quiet = true;
this.err( HMSTATUS.readError, obj.ex );
}
}
this.setError( errCode, obj.ex );
this.err( errCode, obj.ex );
}
}, this);

View File

@ -38,7 +38,9 @@ Implementation of the 'validate' verb for HackMyResume.
*/
function validate( sources, unused, opts ) {
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
if( !sources || !sources.length )
throw { fluenterror: HMSTATUS.resumeNotFoundAlt, quit: true };
var isValid = true;
var validator = require('is-my-json-valid');
@ -61,6 +63,7 @@ Implementation of the 'validate' verb for HackMyResume.
// If there was an error reading the resume
if( src.fluenterror ) {
if( opts.assert ) throw src;
this.setError( src.fluenterror, src );
return ret;
}

View File

@ -78,8 +78,19 @@ Definition of the Verb class.
payload.sub = subEvent;
this.fire('status', payload);
return true;
},
/**
Associate error info with the invocation.
*/
setError: function( code, obj ) {
this.errorCode = code;
this.errorObj = obj;
}
});
}());

View File

@ -1,8 +1,8 @@
0|
4|--help
4|-h
4|--debug
4|-d
0|--help
0|-h
0|--debug
0|-d
5|notacommand
3|build
14|build doesnt-exist.json