summaryrefslogtreecommitdiffstats
path: root/lib/cli
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 10:11:33 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 10:11:33 +0100
commit8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019 (patch)
tree8714e7b6155f606260837ae62e45d262c12015a7 /lib/cli
parentdb3d21db49a7260df03ae987b58c495178193dde (diff)
downloadgitbook-8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019.zip
gitbook-8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019.tar.gz
gitbook-8141bcb3b63f16c27f8cd6c5e19aed4b5ef6d019.tar.bz2
Add command 'parse' for gitbook-cli
Diffstat (limited to 'lib/cli')
-rw-r--r--lib/cli/helper.js50
-rw-r--r--lib/cli/index.js44
2 files changed, 94 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
+ }
+};
diff --git a/lib/cli/index.js b/lib/cli/index.js
new file mode 100644
index 0000000..d67b78a
--- /dev/null
+++ b/lib/cli/index.js
@@ -0,0 +1,44 @@
+var Output = require('../output/base');
+var helper = require('./helper');
+
+module.exports = {
+ commands: [
+
+ {
+ name: 'parse [book]',
+ description: 'parse and returns debug information for a book',
+ options: [
+ helper.options.log
+ ],
+ exec: helper.bookCmd(function(book) {
+ return book.parse()
+ .then(function() {
+ book.log.info.ln('');
+
+ if (book.config.exists()) book.log.info.ln('Configuration:', book.config.path);
+
+ if (book.isMultilingual()) {
+ book.log.info.ln('Multilingual book detected:', book.langs.path);
+ } else {
+ book.log.info.ln('Readme:', book.readme.path);
+ book.log.info.ln('Summary:', book.summary.path);
+ if (book.glossary.exists()) book.log.info.ln('Glossary:', book.glossary.path);
+ }
+ });
+ })
+ },
+
+ {
+ name: 'install [book]',
+ description: 'install all plugins dependencies',
+ options: [
+ helper.options.log
+ ],
+ exec: helper.outputCmd(Output, function(output, args) {
+
+ })
+ }
+
+
+ ]
+};