1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-06-16 18:00:06 +01:00

Add baseline support for -d or --debug flag.

For now, -d just force-emits the stack when there is one. In the future,
it can trigger more detailed logging info.
This commit is contained in:
hacksalot 2016-01-08 16:08:33 -05:00
parent f4e763bd9c
commit 9fdfd1b5a6
4 changed files with 23 additions and 16 deletions

View File

@ -1,6 +1,6 @@
{
"name": "hackmyresume",
"version": "1.5.0",
"version": "1.5.1",
"description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.",
"repository": {
"type": "git",

View File

@ -3,7 +3,7 @@ Error-handling routines for HackMyResume.
@module error-handler.js
@license MIT. See LICENSE.md for details.
*/
// TODO: Logging library
(function() {
@ -26,7 +26,9 @@ Error-handling routines for HackMyResume.
*/
var ErrorHandler = module.exports = {
init: function( debug ) {
this.debug = debug;
},
err: function( ex, shouldExit ) {
@ -62,8 +64,10 @@ Error-handling routines for HackMyResume.
log( msg.toString() ) :
log( chalk.red.bold('ERROR: ' + msg.toString()) );
// Usually emit the stack
( showStack && ex.code !== 'ENOENT' ) && log( chalk.gray(ex.stack) );
// Selectively show the stack trace
if( (ex.stack || (ex.inner && ex.inner.stack)) &&
((showStack && ex.code !== 'ENOENT' ) || (this.debug) ))
log( chalk.red( ex.stack || ex.stack.inner ) );
// Let the error code be the process's return code.
( shouldExit || ex.shouldExit ) && process.exit( exitCode );

View File

@ -47,8 +47,8 @@ Definition of the HtmlPdfCLIGenerator class.
// { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', ... }
// { [Error: ENOENT] }
throw ( ex.inner && ex.inner.code === 'ENOENT' ) ?
{ fluenterror: this.codes.notOnPath, engine: ex.cmd } :
{ fluenterror: this.codes.pdfGeneration, inner: ex.inner };
{ fluenterror: this.codes.notOnPath, engine: ex.cmd, stack: ex.inner.stack } :
{ fluenterror: this.codes.pdfGeneration, inner: ex.inner, stack: ex.inner.stack };
}
}

View File

@ -49,7 +49,8 @@ function main() {
.option('-o --opts <optionsFile>', 'Path to a .hackmyrc options file')
.option('-s --silent', 'Run in silent mode')
.option('--no-color', 'Disable colors')
.option('--color', 'Enable colors');
.option('--color', 'Enable colors')
.option('-d --debug', 'Enable diagnostics', false);
//.usage('COMMAND <sources> [TO <targets>]');
// Create the NEW command
@ -172,6 +173,7 @@ Invoke a HackMyResume verb.
*/
function execVerb( src, dst, opts, log ) {
loadOptions.call( this, opts );
require('./core/error-handler').init( _opts.debug );
HMR.verbs[ this.name() ].call( null, src, dst, _opts, log );
}
@ -180,23 +182,24 @@ function execVerb( src, dst, opts, log ) {
/**
Initialize HackMyResume options.
*/
function loadOptions( opts ) {
function loadOptions( o ) {
opts.opts = this.parent.opts;
o.opts = this.parent.opts;
// Load the specified options file (if any) and apply options
if( opts.opts && String.is( opts.opts )) {
var json = safeLoadJSON( PATH.relative( process.cwd(), opts.opts ) );
json && ( opts = EXTEND( true, opts, json ) );
if( o.opts && String.is( o.opts )) {
var json = safeLoadJSON( PATH.relative( process.cwd(), o.opts ) );
json && ( o = EXTEND( true, o, json ) );
if( !json ) {
throw safeLoadJSON.error;
}
}
// Merge in command-line options
opts = EXTEND( true, opts, this.opts() );
opts.silent = this.parent.silent;
_opts = opts;
o = EXTEND( true, o, this.opts() );
o.silent = this.parent.silent;
o.debug = this.parent.debug;
_opts = o;
}