CLI: -v option for displaying current versiontags/v1.2.0
| @@ -8,7 +8,7 @@ var pkg = require('../package'); | |||||
| var viewArg = process.argv[2]; | var viewArg = process.argv[2]; | ||||
| var templateArg = process.argv[3]; | var templateArg = process.argv[3]; | ||||
| if (process.argv.indexOf('--version') > -1) { | |||||
| if (hasVersionArg()) { | |||||
| return console.log(pkg.version); | return console.log(pkg.version); | ||||
| } | } | ||||
| @@ -87,3 +87,9 @@ function isStdin(viewArg) { | |||||
| function wasNotFound(err) { | function wasNotFound(err) { | ||||
| return err.code && err.code === 'ENOENT'; | return err.code && err.code === 'ENOENT'; | ||||
| } | } | ||||
| function hasVersionArg() { | |||||
| return ['--version', '-v'].some(function(opt) { | |||||
| return process.argv.indexOf(opt) > -1; | |||||
| }); | |||||
| } | |||||
| @@ -35,6 +35,13 @@ describe('Mustache CLI', function () { | |||||
| }); | }); | ||||
| }); | }); | ||||
| it('writes module version into stdout when runned with -v', function(done){ | |||||
| exec('bin/mustache -v', function(err, stdout, stderr) { | |||||
| assert.notEqual(stdout.indexOf(moduleVersion), -1); | |||||
| done(); | |||||
| }); | |||||
| }); | |||||
| it('writes rendered template into stdout when successfull', function(done) { | it('writes rendered template into stdout when successfull', function(done) { | ||||
| exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function(err, stdout, stderr) { | exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function(err, stdout, stderr) { | ||||
| assert.equal(err, null); | assert.equal(err, null); | ||||