diff --git a/bin/mustache b/bin/mustache index 4b3f0c1..367fab5 100755 --- a/bin/mustache +++ b/bin/mustache @@ -8,7 +8,7 @@ var pkg = require('../package'); var viewArg = process.argv[2]; var templateArg = process.argv[3]; -if (process.argv.indexOf('--version') > -1) { +if (hasVersionArg()) { return console.log(pkg.version); } @@ -87,3 +87,9 @@ function isStdin(viewArg) { function wasNotFound(err) { return err.code && err.code === 'ENOENT'; } + +function hasVersionArg() { + return ['--version', '-v'].some(function(opt) { + return process.argv.indexOf(opt) > -1; + }); +} \ No newline at end of file diff --git a/test/cli-test.js b/test/cli-test.js index 39940c3..4db29f4 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -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) { exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function(err, stdout, stderr) { assert.equal(err, null);