diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-17 10:11:33 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-17 10:11:33 +0100 |
commit | 8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019 (patch) | |
tree | 8714e7b6155f606260837ae62e45d262c12015a7 /lib/cli/helper.js | |
parent | db3d21db49a7260df03ae987b58c495178193dde (diff) | |
download | gitbook-8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019.zip gitbook-8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019.tar.gz gitbook-8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019.tar.bz2 |
Add command 'parse' for gitbook-cli
Diffstat (limited to 'lib/cli/helper.js')
-rw-r--r-- | lib/cli/helper.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/cli/helper.js b/lib/cli/helper.js new file mode 100644 index 0000000..67bc502 --- /dev/null +++ b/lib/cli/helper.js @@ -0,0 +1,50 @@ +var _ = require('lodash'); + +var Book = require('../book'); +var NodeFS = require('../fs/node'); +var Logger = require('../utils/logger'); + +var LOG_OPTION = { + name: 'log', + description: 'Minimum log level to display', + values: _.chain(Logger.LEVELS) + .keys() + .map(function(s) { + return s.toLowerCase(); + }) + .value(), + defaults: 'info' +}; + +// Commands which is processing a book +// the root of the book is the first argument (or current directory) +function bookCmd(fn) { + return function(args, kwargs) { + + var input = args[0] || process.cwd(); + var book = new Book({ + fs: new NodeFS(), + root: input, + + logLevel: kwargs.log + }); + + return fn(book, args.slice(1)); + }; +} + +// Commands which is working on a Output instance +function outputCmd(Out, fn) { + return bookCmd(function(book, args) { + return fn(new Out(book), args); + }); +} + +module.exports = { + bookCmd: bookCmd, + outputCmd: outputCmd, + + options: { + log: LOG_OPTION + } +}; |