1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 01:56:21 +00:00

Improve PEEK behavior.

This commit is contained in:
hacksalot 2016-02-02 17:34:10 -05:00
parent d7c83613df
commit 11dd8952d8
4 changed files with 40 additions and 22 deletions

2
dist/cli/out.js vendored
View File

@ -154,6 +154,8 @@ Output routines for HackMyResume.
}); });
} else if (!evt.error) { } else if (!evt.error) {
return L(M2C(this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file); return L(M2C(this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file);
} else if (evt.error) {
return L(chalk.red(evt.error.inner.inner));
} }
} }
}; };

27
dist/verbs/peek.js vendored
View File

@ -51,10 +51,11 @@ Implementation of the 'peek' verb for HackMyResume.
return {}; return {};
} }
tgt = _peekOne.call(this, t, objPath); tgt = _peekOne.call(this, t, objPath);
if (tgt.fluenterror) { if (tgt.error) {
tgt.quit = opts.assert; tgt.quit = opts.assert;
return this.err(tgt.fluenterror, tgt); this.err(tgt.fluenterror, tgt);
} }
return tgt;
}, this); }, this);
if (this.hasError() && !opts.assert) { if (this.hasError() && !opts.assert) {
this.reject(this.errorCode); this.reject(this.errorCode);
@ -68,7 +69,7 @@ Implementation of the 'peek' verb for HackMyResume.
/** Peek at a single resume, resume section, or resume field. */ /** Peek at a single resume, resume section, or resume field. */
_peekOne = function(t, objPath) { _peekOne = function(t, objPath) {
var errCode, obj, tgt; var errCode, obj, pkgError, tgt;
this.stat(HMEVENT.beforePeek, { this.stat(HMEVENT.beforePeek, {
file: t, file: t,
target: objPath target: objPath
@ -78,23 +79,27 @@ Implementation of the 'peek' verb for HackMyResume.
if (!obj.ex) { if (!obj.ex) {
tgt = objPath ? __.get(obj.json, objPath) : obj.json; tgt = objPath ? __.get(obj.json, objPath) : obj.json;
} }
this.stat(HMEVENT.afterPeek, { pkgError = null;
file: t,
requested: objPath,
target: tgt,
error: obj.ex
});
if (obj.ex) { if (obj.ex) {
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError; errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
if (errCode === HMSTATUS.readError) { if (errCode === HMSTATUS.readError) {
obj.ex.quiet = true; obj.ex.quiet = true;
} }
return { pkgError = {
fluenterror: errCode, fluenterror: errCode,
inner: obj.ex inner: obj.ex
}; };
} }
return tgt; this.stat(HMEVENT.afterPeek, {
file: t,
requested: objPath,
target: obj.ex ? void 0 : tgt,
error: pkgError
});
return {
val: tgt,
errpr: pkgError
};
}; };
}).call(this); }).call(this);

View File

@ -157,12 +157,20 @@ module.exports = class OutputHandler
when HME.afterPeek when HME.afterPeek
sty = if evt.error then 'red' else ( if evt.target != undefined then 'green' else 'yellow' ) sty = if evt.error then 'red' else ( if evt.target != undefined then 'green' else 'yellow' )
# "Peeking at 'someKey' in 'someFile'."
if evt.requested if evt.requested
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file) L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file)
else else
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file) L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file)
# If the key was present, print it
if evt.target != undefined if evt.target != undefined
console.dir( evt.target, { depth: null, colors: true } ) console.dir( evt.target, { depth: null, colors: true } )
# If the key was not present, but no error occurred, print it
else if !evt.error 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);
else if evt.error
L( chalk.red( evt.error.inner.inner ));

View File

@ -33,9 +33,10 @@ _peek = ( src, dst, opts ) ->
results = _.map src, ( t ) -> results = _.map src, ( t ) ->
return { } if opts.assert and @hasError() return { } if opts.assert and @hasError()
tgt = _peekOne.call @, t, objPath tgt = _peekOne.call @, t, objPath
if tgt.fluenterror if tgt.error
tgt.quit = opts.assert tgt.quit = opts.assert
@err tgt.fluenterror, tgt @err tgt.fluenterror, tgt
tgt
, @ , @
if @hasError() and !opts.assert if @hasError() and !opts.assert
@ -49,7 +50,7 @@ _peek = ( src, dst, opts ) ->
###* Peek at a single resume, resume section, or resume field. ### ###* Peek at a single resume, resume section, or resume field. ###
_peekOne = ( t, objPath ) -> _peekOne = ( t, objPath ) ->
@.stat HMEVENT.beforePeek, { file: t, target: objPath } @stat HMEVENT.beforePeek, { file: t, target: objPath }
# Load the input file JSON 1st # Load the input file JSON 1st
obj = safeLoadJSON t obj = safeLoadJSON t
@ -59,18 +60,20 @@ _peekOne = ( t, objPath ) ->
if !obj.ex if !obj.ex
tgt = if objPath then __.get obj.json, objPath else obj.json; tgt = if objPath then __.get obj.json, objPath else obj.json;
# Fire the 'afterPeek' event with collected info
@.stat HMEVENT.afterPeek,
file: t
requested: objPath
target: tgt
error: obj.ex
## safeLoadJSON can only return a READ error or a PARSE error ## safeLoadJSON can only return a READ error or a PARSE error
pkgError = null
if obj.ex if obj.ex
errCode = if obj.ex.operation == 'parse' then HMSTATUS.parseError else HMSTATUS.readError errCode = if obj.ex.operation == 'parse' then HMSTATUS.parseError else HMSTATUS.readError
if errCode == HMSTATUS.readError if errCode == HMSTATUS.readError
obj.ex.quiet = true obj.ex.quiet = true
return fluenterror: errCode, inner: obj.ex pkgError = fluenterror: errCode, inner: obj.ex
tgt
# Fire the 'afterPeek' event with collected info
@stat HMEVENT.afterPeek,
file: t
requested: objPath
target: if obj.ex then undefined else tgt
error: pkgError
val: tgt, errpr: pkgError