From 13430bcad52e52c36d6591cfb57287b95f6b6f62 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Tue, 29 Dec 2015 05:09:05 -0500 Subject: [PATCH] Refactor status codes. --- src/core/status-codes.js | 21 ++++++++++++++++ src/gen/base-generator.js | 9 +------ src/index.js | 50 +++++++++++++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 src/core/status-codes.js diff --git a/src/core/status-codes.js b/src/core/status-codes.js new file mode 100644 index 0000000..d0467c7 --- /dev/null +++ b/src/core/status-codes.js @@ -0,0 +1,21 @@ +/** +Status codes for HackMyResume. +@module status-codes.js +*/ + +(function(){ + + module.exports = { + success: 0, + themeNotFound: 1, + copyCss: 2, + resumeNotFound: 3, + missingCommand: 4, + invalidCommand: 5, + resumeNotFoundAlt: 6, + inputOutputParity: 7, + createNameMissing: 8, + wkhtmltopdf: 9 + }; + +}()); diff --git a/src/gen/base-generator.js b/src/gen/base-generator.js index 9e1bc89..5d11777 100644 --- a/src/gen/base-generator.js +++ b/src/gen/base-generator.js @@ -26,14 +26,7 @@ Definition of the BaseGenerator class. /** Status codes. */ - codes: { - success: 0, - themeNotFound: 1, - copyCss: 2, - resumeNotFound: 3, - missingCommand: 4, - invalidCommand: 5 - }, + codes: require('../core/status-codes'), /** Generator options. diff --git a/src/index.js b/src/index.js index 5b65b71..07081da 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,7 @@ var ARGS = require( 'minimist' ) , COLORS = require('colors') , FS = require('fs') , PATH = require('path') + , HACKMYSTATUS = require('./core/status-codes') , opts = { } , title = ('\n*** HackMyResume v' + PKG.version + ' ***').bold.white , _ = require('underscore'); @@ -99,20 +100,49 @@ function handleError( ex ) { if( ex.fluenterror ){ switch( ex.fluenterror ) { // TODO: Remove magic numbers - case 1: msg = "The specified theme couldn't be found: " + ex.data; break; - case 2: msg = "Couldn't copy CSS file to destination folder"; break; - case 3: msg = 'Please '.guide + 'specify a valid input resume'.guide.bold + ' in FRESH or JSON Resume format.'.guide; break; - case 4: msg = title + "\nPlease ".guide + "specify a command".guide.bold + " (".guide + + + case HACKMYSTATUS.themeNotFound: + msg = "The specified theme couldn't be found: " + ex.data; + break; + + case HACKMYSTATUS.copyCSS: + msg = "Couldn't copy CSS file to destination folder"; + break; + + case HACKMYSTATUS.resumeNotFound: + msg = 'Please '.guide + 'specify a valid input resume'.guide.bold + + ' in FRESH or JSON Resume format.'.guide; + break; + + case HACKMYSTATUS.missingCommand: + msg = title + "\nPlease ".guide + "specify a command".guide.bold + " (".guide + Object.keys( FCMD.verbs ).map( function(v, idx, ar) { return (idx === ar.length - 1 ? 'or '.guide : '') + v.toUpperCase().guide; - }).join(', '.guide) + ").\n\n".guide + FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' ).info.bold; + }).join(', '.guide) + ").\n\n".guide + + FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' ).info.bold; break; - //case 4: msg = title + '\n' + ; break; - case 5: msg = 'Please '.guide + 'specify the output resume file'.guide.bold + ' that should be created.'.guide; break; - case 6: msg = 'Please '.guide + 'specify a valid input resume'.guide.bold + ' in either FRESH or JSON Resume format.'.guide; break; - case 7: msg = 'Please '.guide + 'specify an output file name'.guide.bold + ' for every input file you wish to convert.'.guide; break; - case 8: msg = 'Please '.guide + 'specify the filename of the resume'.guide.bold + ' to create.'.guide; break; + + case HACKMYSTATUS.invalidCommand: + msg = 'Please '.guide + 'specify the output resume file'.guide.bold + + ' that should be created.'.guide; + break; + + case HACKMYSTATUS.resumeNotFoundAlt: + msg = 'Please '.guide + 'specify a valid input resume'.guide.bold + + ' in either FRESH or JSON Resume format.'.guide; + break; + + case HACKMYSTATUS.inputOutputParity: + msg = 'Please '.guide + 'specify an output file name'.guide.bold + + ' for every input file you wish to convert.'.guide; + break; + + case HACKMYSTATUS.createNameMissing: + msg = 'Please '.guide + 'specify the filename of the resume'.guide.bold + + ' to create.'.guide; + break; + } exitCode = ex.fluenterror;