1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 00:10:15 +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) {
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 {};
}
tgt = _peekOne.call(this, t, objPath);
if (tgt.fluenterror) {
if (tgt.error) {
tgt.quit = opts.assert;
return this.err(tgt.fluenterror, tgt);
this.err(tgt.fluenterror, tgt);
}
return tgt;
}, this);
if (this.hasError() && !opts.assert) {
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. */
_peekOne = function(t, objPath) {
var errCode, obj, tgt;
var errCode, obj, pkgError, tgt;
this.stat(HMEVENT.beforePeek, {
file: t,
target: objPath
@ -78,23 +79,27 @@ Implementation of the 'peek' verb for HackMyResume.
if (!obj.ex) {
tgt = objPath ? __.get(obj.json, objPath) : obj.json;
}
this.stat(HMEVENT.afterPeek, {
file: t,
requested: objPath,
target: tgt,
error: obj.ex
});
pkgError = null;
if (obj.ex) {
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
if (errCode === HMSTATUS.readError) {
obj.ex.quiet = true;
}
return {
pkgError = {
fluenterror: errCode,
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);

View File

@ -157,12 +157,20 @@ module.exports = class OutputHandler
when HME.afterPeek
sty = if evt.error then 'red' else ( if evt.target != undefined then 'green' else 'yellow' )
# "Peeking at 'someKey' in 'someFile'."
if evt.requested
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file)
else
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file)
# If the key was present, print it
if evt.target != undefined
console.dir( evt.target, { depth: null, colors: true } )
# If the key was not present, but no error occurred, print it
else if !evt.error
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 ) ->
return { } if opts.assert and @hasError()
tgt = _peekOne.call @, t, objPath
if tgt.fluenterror
if tgt.error
tgt.quit = opts.assert
@err tgt.fluenterror, tgt
tgt
, @
if @hasError() and !opts.assert
@ -49,7 +50,7 @@ _peek = ( src, dst, opts ) ->
###* Peek at a single resume, resume section, or resume field. ###
_peekOne = ( t, objPath ) ->
@.stat HMEVENT.beforePeek, { file: t, target: objPath }
@stat HMEVENT.beforePeek, { file: t, target: objPath }
# Load the input file JSON 1st
obj = safeLoadJSON t
@ -59,18 +60,20 @@ _peekOne = ( t, objPath ) ->
if !obj.ex
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
pkgError = null
if obj.ex
errCode = if obj.ex.operation == 'parse' then HMSTATUS.parseError else HMSTATUS.readError
if errCode == HMSTATUS.readError
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