Skip to content

Commit

Permalink
Add support for custom options
Browse files Browse the repository at this point in the history
  • Loading branch information
pvorb committed Dec 30, 2011
1 parent badad80 commit 2ceb0b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions bin/tpl
Expand Up @@ -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', {
Expand All @@ -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());
Expand All @@ -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);
});
}
5 changes: 3 additions & 2 deletions tpl.js
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2ceb0b7

Please sign in to comment.