Permalink
Browse files

Add command init

  • Loading branch information...
1 parent 48695b9 commit d50e8fa877f2db2a213df977590affe97d9b3142 @pvorb committed Jan 15, 2012
Showing with 18 additions and 1 deletion.
  1. +18 −1 bin/tpl
View
19 bin/tpl
@@ -1,7 +1,11 @@
#!/usr/bin/env node
+var fs = require('fs');
+var path = require('path');
+
var optimist = require('optimist')
- .usage(' tpl [options] [file] Apply a template to a file\n'
+ .usage(' tpl init Create a basic configuration directory\n'
+ + ' tpl [options] [file] Apply a template to a file\n'
+ ' tpl [-h|--help] Show help');
var argv = optimist.argv;
@@ -17,6 +21,19 @@ else if (argv._.length == 0) {
else if (argv._.length > 1) {
console.error('tpl can only translate one file at a time.');
}
+else if (argv._.length == 1 && argv._[0] == 'init') {
+ var confdir = path.resolve(process.cwd(), '.tpl');
+ try {
+ fs.mkdirSync(confdir);
+ fs.writeFileSync(path.resolve(confdir, 'conf.json'));
+ fs.mkdirSync(path.resolve(confdir, 'templates'));
+ fs.mkdirSync(path.resolve(confdir, 'parsers'));
+ console.log('Created the configuration directory \''+confdir+'\'.');
+ } catch (e) {
+ console.error('Could not create the configuration directory \''+confdir
+ +'\'.');
+ }
+}
// Translate file
else {
var file = require('path').resolve(process.cwd(), argv._[0]);

0 comments on commit d50e8fa

Please sign in to comment.