Skip to content

Commit

Permalink
add --version to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinr committed Feb 10, 2014
1 parent b76b2ff commit fef349a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10847,6 +10847,7 @@ declare module Lint {
private fileName;
private source;
private options;
static VERSION: string;
constructor(fileName: string, source: string, options: any);
public lint(): LintResult;
private getRelativePath(directory);
Expand Down
24 changes: 18 additions & 6 deletions src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var path = require("path");
var optimist = require("optimist")
.usage("usage: $0")
.check((argv) => {
// f is required unless we're asking for help; throw an error if f is missing unless help is there
if (!("f" in argv) && !("help" in argv)) {
// at least one of file or help or version must be present
if (!(argv.f || argv.h || argv.v)) {
throw "Missing required arguments: f";
}
})
Expand All @@ -35,6 +35,10 @@ var optimist = require("optimist")
alias: "file",
describe: "file to lint"
},
"h": {
alias: "help",
describe: "display detailed help"
},
"o": {
alias: "out",
describe: "output file"
Expand All @@ -52,10 +56,10 @@ var optimist = require("optimist")
describe: "output format (prose, json, verbose)",
default: "prose"
},
"h": {
alias: "help",
describe: "display detailed help"
},
"v": {
alias: "version",
describe: "current version"
}
});
var argv = optimist.argv;

Expand All @@ -70,6 +74,11 @@ if (argv.o !== undefined) {
outputStream = process.stdout;
}

if (argv.v !== undefined) {
outputStream.write(Lint.Linter.VERSION + "\n");
process.exit(0);
}

if ("help" in argv) {
outputStream.write(optimist.help());
var outputString = "\ntslint accepts the following commandline options:\n" +
Expand Down Expand Up @@ -119,6 +128,9 @@ if ("help" in argv) {
" and verbose. prose is the default if this option is not used. Additonal\n" +
" formatters can be added and used if the --formatters-dir option is set.\n" +
"\n" +
" -v, --version:\n" +
" The current version of tslint.\n" +
"\n" +
" -h, --help:\n" +
" Prints this help message.\n";
outputStream.write(outputString);
Expand Down
2 changes: 2 additions & 0 deletions src/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module Lint {
private source: string;
private options: any;

public static VERSION = "0.4.2";

constructor(fileName: string, source: string, options: any) {
this.fileName = fileName;
this.source = source;
Expand Down

0 comments on commit fef349a

Please sign in to comment.