Permalink
Browse files

Add support for custom options

  • Loading branch information...
1 parent badad80 commit 2ceb0b70ccd0c7a9a95370484766646e8dac8131 @pvorb committed Dec 30, 2011
Showing with 8 additions and 8 deletions.
  1. +5 −6 bin/tpl
  2. +3 −2 tpl.js
View
11 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);
});
}
View
5 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

0 comments on commit 2ceb0b7

Please sign in to comment.