summaryrefslogtreecommitdiffstats
path: root/lib/cli/helper.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cli/helper.js')
-rw-r--r--lib/cli/helper.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/cli/helper.js b/lib/cli/helper.js
index 67bc502..61b9957 100644
--- a/lib/cli/helper.js
+++ b/lib/cli/helper.js
@@ -3,6 +3,9 @@ var _ = require('lodash');
var Book = require('../book');
var NodeFS = require('../fs/node');
var Logger = require('../utils/logger');
+var JSONOutput = require('../output/json');
+var WebsiteOutput = require('../output/website');
+var EBookOutput = require('../output/ebook');
var LOG_OPTION = {
name: 'log',
@@ -16,6 +19,19 @@ var LOG_OPTION = {
defaults: 'info'
};
+var FORMAT_OPTION = {
+ name: 'format',
+ description: 'Format to build to',
+ values: ['website', 'json', 'ebook'],
+ defaults: 'website'
+};
+
+var FORMATS = {
+ json: JSONOutput,
+ website: WebsiteOutput,
+ ebook: EBookOutput
+};
+
// Commands which is processing a book
// the root of the book is the first argument (or current directory)
function bookCmd(fn) {
@@ -29,13 +45,14 @@ function bookCmd(fn) {
logLevel: kwargs.log
});
- return fn(book, args.slice(1));
+ return fn(book, args.slice(1), kwargs);
};
}
// Commands which is working on a Output instance
-function outputCmd(Out, fn) {
- return bookCmd(function(book, args) {
+function outputCmd(fn) {
+ return bookCmd(function(book, args, kwargs) {
+ var Out = FORMATS[kwargs.format];
return fn(new Out(book), args);
});
}
@@ -45,6 +62,7 @@ module.exports = {
outputCmd: outputCmd,
options: {
- log: LOG_OPTION
+ log: LOG_OPTION,
+ format: FORMAT_OPTION
}
};