diff options
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 + } +}; |