mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-07-09 11:41:07 +01:00
CONVERT: Improve command consistency.
This commit is contained in:
@ -26,10 +26,14 @@ formats. ###
|
||||
|
||||
_convert = ( srcs, dst, opts ) ->
|
||||
|
||||
# Housekeeping...
|
||||
# If no source resumes are specified, error out
|
||||
if !srcs || !srcs.length
|
||||
@err HMSTATUS.resumeNotFound, { quit: true }
|
||||
return null
|
||||
|
||||
# If no destination resumes are specified, error out except for the special
|
||||
# case of two resumes:
|
||||
# hackmyresume CONVERT r1.json r2.json
|
||||
if !dst || !dst.length
|
||||
if srcs.length == 1
|
||||
@err HMSTATUS.inputOutputParity, { quit: true }
|
||||
@ -37,19 +41,30 @@ _convert = ( srcs, dst, opts ) ->
|
||||
dst = dst || []; dst.push( srcs.pop() )
|
||||
else
|
||||
@err HMSTATUS.inputOutputParity, { quit: true }
|
||||
|
||||
# Different number of source and dest resumes? Error out.
|
||||
if srcs && dst && srcs.length && dst.length && srcs.length != dst.length
|
||||
@err HMSTATUS.inputOutputParity, { quit: true }
|
||||
|
||||
# Load source resumes
|
||||
# If any errors have occurred this early, we're done.
|
||||
if @hasError()
|
||||
@reject @errorCode
|
||||
return null
|
||||
|
||||
# Map each source resume to the converted destination resume
|
||||
results = _.map srcs, ( src, idx ) ->
|
||||
return { } if opts.assert and @hasError()
|
||||
|
||||
# Convert each resume in turn
|
||||
r = _convertOne.call @, src, dst, idx
|
||||
|
||||
# Handle conversion errors
|
||||
if r.fluenterror
|
||||
r.quit = opts.assert
|
||||
@err r.fluenterror, r
|
||||
r
|
||||
, @
|
||||
|
||||
|
||||
if @hasError() and !opts.assert
|
||||
@reject results
|
||||
else if !@hasError()
|
||||
@ -60,17 +75,31 @@ _convert = ( srcs, dst, opts ) ->
|
||||
|
||||
###* Private workhorse method. Convert a single resume. ###
|
||||
_convertOne = (src, dst, idx) ->
|
||||
|
||||
# Load the resume
|
||||
rinfo = ResumeFactory.loadOne src, format: null, objectify: true
|
||||
|
||||
# If a load error occurs, report it and move on to the next file (if any)
|
||||
if rinfo.fluenterror
|
||||
@stat HMEVENT.beforeConvert,
|
||||
srcFile: src #rinfo.file
|
||||
srcFmt: '???'
|
||||
dstFile: dst[idx]
|
||||
dstFmt: '???'
|
||||
error: true
|
||||
#@err rinfo.fluenterror, rinfo
|
||||
return rinfo
|
||||
|
||||
rez = rinfo.rez
|
||||
srcFmt = ''
|
||||
if rez.meta && rez.meta.format #&& rez.meta.format.substr(0, 5).toUpperCase() == 'FRESH'
|
||||
srcFmt = 'FRESH'
|
||||
else if rez.basics
|
||||
srcFmt = 'JRS'
|
||||
else
|
||||
rinfo.fluenterror = HMSTATUS.unknownSchema
|
||||
return rinfo
|
||||
|
||||
s = rinfo.rez
|
||||
srcFmt =
|
||||
if ((s.basics && s.basics.imp) || s.imp).orgFormat == 'JRS'
|
||||
then 'JRS' else 'FRESH'
|
||||
targetFormat = if srcFmt == 'JRS' then 'FRESH' else 'JRS'
|
||||
|
||||
this.stat HMEVENT.beforeConvert,
|
||||
@ -80,5 +109,5 @@ _convertOne = (src, dst, idx) ->
|
||||
dstFmt: targetFormat
|
||||
|
||||
# Save it to the destination format
|
||||
s.saveAs dst[idx], targetFormat
|
||||
s
|
||||
rez.saveAs dst[idx], targetFormat
|
||||
rez
|
||||
|
@ -32,12 +32,20 @@ module.exports = class Verb
|
||||
|
||||
###* Invoke the command. ###
|
||||
invoke: ->
|
||||
|
||||
# Sent the 'begin' notification for this verb
|
||||
@stat HMEVENT.begin, cmd: @moniker
|
||||
|
||||
# Prepare command arguments
|
||||
argsArray = Array::slice.call arguments
|
||||
|
||||
# Create a promise for this verb instance
|
||||
that = @
|
||||
@promise = new Promise (res, rej) ->
|
||||
that.resolve = res; that.reject = rej
|
||||
that.workhorse.apply that, argsArray; return
|
||||
that.resolve = res
|
||||
that.reject = rej
|
||||
that.workhorse.apply that, argsArray
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user