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

Improve PEEK command behavior.

This commit is contained in:
hacksalot 2016-01-18 19:20:17 -05:00
parent a81ad0fef2
commit 181419ae28
2 changed files with 32 additions and 14 deletions

View File

@ -197,16 +197,22 @@ Output routines for HackMyResume.
break; break;
case HME.beforePeek: case HME.beforePeek:
if( evt.target ) // if( evt.target )
L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file); // L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
else // else
L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file); // L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
break; break;
case HME.afterPeek: case HME.afterPeek:
if( evt.target ) var sty = evt.error ? 'red' : ( evt.target !== undefined ? 'green' : 'yellow' );
console.dir( evt.target, { depth: null, colors: true } ); if( evt.requested )
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file);
else else
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file);
if( evt.target !== undefined )
console.dir( evt.target, { depth: null, colors: true } );
else if( !evt.error )
L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file); L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file);
break; break;

View File

@ -46,9 +46,26 @@ Implementation of the 'peek' verb for HackMyResume.
_.each( src, function( t ) { _.each( src, function( t ) {
var obj = safeLoadJSON( t ); // Fire the 'beforePeek' event 2nd, so we have error/warning/success
this.stat( HMEVENT.beforePeek, { file: t, target: objPath, isError: obj.ex } ); this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
// Load the input file JSON 1st
var obj = safeLoadJSON( t );
// Fetch the requested object path (or the entire file)
var tgt;
if( !obj.ex )
tgt = objPath ? __.get( obj.json, objPath ) : obj.json;
// Fire the 'afterPeek' event with collected info
this.stat( HMEVENT.afterPeek, {
file: t,
requested: objPath,
target: tgt,
error: obj.ex
});
// safeLoadJSON can only return a READ error or a PARSE error
if( obj.ex ) { if( obj.ex ) {
if( obj.ex.operation === 'parse' ) if( obj.ex.operation === 'parse' )
this.err( HMSTATUS.parseError, obj.ex ); this.err( HMSTATUS.parseError, obj.ex );
@ -56,13 +73,8 @@ Implementation of the 'peek' verb for HackMyResume.
obj.ex.quiet = true; obj.ex.quiet = true;
this.err( HMSTATUS.readError, obj.ex ); this.err( HMSTATUS.readError, obj.ex );
} }
return;
} }
var targ = objPath ? __.get( obj.json, objPath ) : obj.json;
this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } );
}, this); }, this);
} }