Skip to content

Commit

Permalink
Added -v, --version & -h support to the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Aug 14, 2012
1 parent d3d383a commit dc36562
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions javascript/src/cli/CLI-common.js
Expand Up @@ -9,16 +9,32 @@ YUITest.Util.mix(YUITest.CLI, {
verbose: false,
webcompat: false,
help: false,
version: false,
format: "xunit"
},

outputVersion: function() {
var fs = require('fs'),
path = require('path'),
exists = fs.existsSync || path.existsSync,
pack = path.join(__dirname, 'package.json');

if (exists(pack)) {
var json = JSON.parse(fs.readFileSync(pack, 'utf8'));
this.print(json.version + '\n');
} else {
this.print('Can not locate package.json file.\n');
}
},

outputHelp: function(){
this.print([
"\nUsage: yuitest [options] [file|dir]*",
" ",
"Global Options",
" --groups groupname Run only tests cases that are part of groupname.",
" --help Displays this information.",
" --help, -h Displays this information.",
" --version, -v Displays the current version.",
" --format <format> Specifies output format (junitxml, tap, xunit).",
" --verbose Display informational messages and warnings.",
" --webcompat Load tests designed for use in browsers."
Expand All @@ -31,7 +47,7 @@ YUITest.Util.mix(YUITest.CLI, {
arg = args.shift(),
files = [];

while(arg){
while (arg) {
if (arg.indexOf("--") == 0){
this.options[arg.substring(2)] = true;

Expand All @@ -40,17 +56,31 @@ YUITest.Util.mix(YUITest.CLI, {
this.options[arg.substring(2)] = args.shift();
}
} else {

//see if it's a directory or a file
if (this.isDirectory(arg)){
files = files.concat(this.getFiles(arg));
} else {
files.push(arg);
switch (arg) {
case '-h':
this.options.help = true;
break;
case '-v':
this.options.version = true;
break;
default:
//see if it's a directory or a file
if (this.isDirectory(arg)){
files = files.concat(this.getFiles(arg));
} else {
files.push(arg);
}

}
}
arg = args.shift();
}

if (this.options.version) {
this.outputVersion();
this.quit(0);
}

if (this.options.help || files.length === 0){
this.outputHelp();
this.quit(0);
Expand Down

0 comments on commit dc36562

Please sign in to comment.