From 2ceb0b70ccd0c7a9a95370484766646e8dac8131 Mon Sep 17 00:00:00 2001 From: Paul Vorbach Date: Fri, 30 Dec 2011 23:30:56 +0100 Subject: [PATCH] Add support for custom options --- bin/tpl | 11 +++++------ tpl.js | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/tpl b/bin/tpl index de1203c..908f370 100644 --- a/bin/tpl +++ b/bin/tpl @@ -2,7 +2,7 @@ var optimist = require('optimist') .usage('Usage:\n' - + 'tpl [file]\n' + + 'tpl [options] [file]\n' + 'tpl [-v|--version]\n' + 'tpl [-h|--help]') .options('v', { @@ -23,10 +23,6 @@ if (argv.v) { else if (argv.h) { console.log(optimist.help()); } -// Show unknown command -else if (Object.keys(argv).length > 2) { - console.error('Unknown command'); -} // Show help else if (argv._.length == 0) { console.log(optimist.help()); @@ -39,7 +35,10 @@ else if (argv._.length > 1) { else { var file = require('path').resolve(process.cwd(), argv._[0]); - require('tpl').apply(file, function(err, result) { + delete argv._; + delete argv['$0']; + + require('../tpl.js').apply(file, argv, function(err, result) { console.log(result); }); } diff --git a/tpl.js b/tpl.js index f72664b..1ce9379 100644 --- a/tpl.js +++ b/tpl.js @@ -23,7 +23,7 @@ var defaultConf = { } }; -function apply(file, cb) { +function apply(file, opt, cb) { // look for configuration directory confdir(process.cwd(), 'tpl', function(err, dir) { try { @@ -47,7 +47,8 @@ function apply(file, cb) { parser = require(path.resolve(dir, 'parsers', parser + '.js')); // parse file - var doc = parser(file); + var doc = append(opt, parser(file)); + console.log(doc); var tpl; // determine template and engine