support -v option; provide more detailed version info (#303)

This commit is contained in:
Jeff Williams 2013-01-17 18:06:31 -08:00
parent dd4b4a4f60
commit b814da3e8b
3 changed files with 12 additions and 3 deletions

View File

@ -113,6 +113,7 @@ function main() {
var exampleConf;
var filter;
var i;
var info;
var l;
var packageDocs;
var packageJson;
@ -216,8 +217,9 @@ function main() {
include('test/runner.js');
process.exit(0);
} else if (env.opts.version) {
var info = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
console.log(info.version);
info = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
info.revision = new Date(parseInt(info.revision, 10)).toUTCString();
console.log('JSDoc ' + info.version + ' (' + info.revision + ')');
process.exit(0);
}

View File

@ -79,7 +79,7 @@ argParser.addOption('h', 'help', false, 'Print this message and quit.');
argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.');
argParser.addOption('q', 'query', true, 'A query string to parse and store in env.opts.query. Example: foo=bar&baz=true', false, parseQuery);
argParser.addOption('u', 'tutorials', true, 'Directory in which JSDoc should search for tutorials.');
argParser.addOption(null,'version', false, 'Display the version number and quit.');
argParser.addOption('v', 'version', false, 'Display the version number and quit.');
//TODO [-R, recurseonly] = a number representing the depth to recurse
//TODO [-f, filter] = a regex to filter on <-- this can be better defined in the configs?

View File

@ -233,6 +233,13 @@ describe("jsdoc/opts/args", function() {
expect(r.nocolor).toEqual(true);
});
it("should accept a '-v' option and return an object with a 'version' property", function() {
args.parse(['-v']);
var r = args.get();
expect(r.version).toEqual(true);
});
it("should accept a '--version' option and return an object with a 'version' property", function() {
args.parse(['--version']);
var r = args.get();