Skip to content

Commit

Permalink
cleaned up options parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jdan committed Aug 27, 2014
1 parent 8e075bc commit 57f032e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 4 additions & 13 deletions bin/cleaver
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require('path');
var fs = require('fs');
var program = require('commander');
var pluck = require('../lib/pluck');
var Cleaver;

/**
Expand Down Expand Up @@ -70,19 +71,9 @@ program

program.parse(process.argv);

// TODO: a lot of code duplication here
var parsedOpts = {
title: program.title,
theme: program.theme,
style: program.style,
output: program.output,
controls: program.controls,
progress: program.progress,
encoding: program.encoding,
template: program.template,
layout: program.layout,
debug: program.debug
};
var parsedOpts = pluck(program, [
'title', 'theme', 'style', 'output', 'controls', 'progress', 'encoding',
'template', 'layout', 'debug']);

if (!program.args.length) {
// TODO: custom help screen
Expand Down
15 changes: 15 additions & 0 deletions lib/pluck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Plucks a few fields from an object
*/
function pluck(obj, fields) {
var plucked = {};
if (!obj) return;

fields.forEach(function (field) {
plucked[field] = obj[field];
});

return plucked;
};

module.exports = pluck;

0 comments on commit 57f032e

Please sign in to comment.