Skip to content

Commit

Permalink
Adding ooti
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Sep 16, 2009
1 parent 8080cb9 commit 3f185b0
Show file tree
Hide file tree
Showing 10 changed files with 544 additions and 12 deletions.
24 changes: 21 additions & 3 deletions bin/ooti
@@ -1,8 +1,26 @@
#!/usr/local/bin/node
var ooti = require('../lib/ooti.js');
var optparse = require('../dep/optparse-js/src/optparse.js');

var SWITCHES = [
['-q', '--quite', 'Only report failed steps'],
];

var parser = new optparse.OptionParser(SWITCHES);

var path, formatterOptions = {};
parser.on(2, function(value) {
path = value;
});

var group = ooti.load(node.path.join(node.cwd(), ARGV[2]));
var formatter = ooti.formatter('cli');
parser.on('quite', function() {
formatterOptions.quite = true;
});

parser.parse(ARGV);

var ooti = require('../lib/ooti.js');
var group = ooti.load(node.path.join(node.cwd(), path));
var formatter = ooti.formatter('cli', formatterOptions);

formatter.observe(group);
group.addListener('group.end', function(stats) {
Expand Down
7 changes: 7 additions & 0 deletions dep/optparse-js/README
@@ -0,0 +1,7 @@
optparse.js 1.0 Alpha

Optparse.js is an Option Parser library for Javascript dialects.

See examples/nodejs-test.js and examples/browser-test-html for more info how to
use the script.

3 changes: 3 additions & 0 deletions dep/optparse-js/TODO
@@ -0,0 +1,3 @@
- Support for Argument lists (for switches)
- Better help formatting
- More documentation
75 changes: 75 additions & 0 deletions dep/optparse-js/examples/browser-test.html
@@ -0,0 +1,75 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>optparse.js example</title>
<script type="text/javascript" charset="utf-8" src="../src/optparse.js"></script>
<script>
// Arguments to be passed to the parser
var ARGS = ['-p', 'This is a message', '-i', 'test.html', '--debug'];

// Define some options
var SWITCHES = [
['-i', '--include-file FILE', "Includes a file"],
['-p', '--print [MESSAGE]', "Prints a message on screen"],
['-d', '--debug', "Enables debug mode"],
];

function puts(msg) {
var body = document.getElementById('body');
var pre = document.createElement('pre');
pre.innerHTML = msg;
body.appendChild(pre);
}

function onLoad() {
puts("optparse.js");

// Create a new OptionParser with defined switches
var parser = new optparse.OptionParser(SWITCHES);

// Internal variable to store options.
var options = {
debug: false,
files: []
};

// Handle the first argument (switches excluded)
parser.on(0, function(value) {
puts("First non-switch argument is: " + value);
});

// Handle the --include-file switch
parser.on('include-file', function(value) {
options.files.push(value);
});

// Handle the --print switch
parser.on('print', function(value) {
puts('PRINT: ' + value);
});

// Handle the --debug switch
parser.on('debug', function() {
options.debug = true;
});

// Parse command line arguments
parser.parse(ARGS);

// Output all files that was included.
puts("No of files to include: " + options.files.length);
for(var i = 0; i < options.files.length; i++) {
puts("File [" + (i + 1) + "]:" + options.files[i]);
}

// Is debug-mode enabled?
puts("Debug mode is set to: " + options.debug);
}
</script>
</head>
<body id="body" onload="onLoad()">

</body>
</html>
82 changes: 82 additions & 0 deletions dep/optparse-js/examples/nodejs-test.js
@@ -0,0 +1,82 @@
// Import the optparse script
var optparse = require('../src/optparse.js');

// Define some options
var SWITCHES = [
['-i', '--include-file FILE', "Includes a file"],
['-p', '--print [MESSAGE]', "Prints an optional message on screen"],
['-d', '--debug', "Enables debug mode"],
['-H', '--help', "Shows this help section"],
['--date DATE', "A date. A date is expected E.G. 2009-01-14"],
['--number NUMBER', "A Number. Supported formats are 123, 123.123, 0xA123"],
];

function onLoad() {
// Create a new OptionParser with defined switches
var parser = new optparse.OptionParser(SWITCHES), print_summary = true,
first_arg;
parser.banner = 'Usage: nodejs-test.js [options]';

// Internal variable to store options.
var options = {
debug: false,
files: [],
number: undefined,
date: undefined
};

// Handle the first argument (switches excluded)
parser.on(0, function(value) {
first_arg = value;
});

// Handle the --include-file switch
parser.on('include-file', function(value) {
options.files.push(value);
});

// Handle the --print switch
parser.on('print', function(value) {
puts('PRINT: ' + (value || 'No message entered'));
});

// Handle the --date switch
parser.on('date', function(value) {
options.date = value;
});

// Handle the --number switch
parser.on('number', function(value) {
options.number = value;
});

// Handle the --debug switch
parser.on('debug', function() {
options.debug = true;
});

// Handle the --help switch
parser.on('help', function() {
puts(parser.toString());
print_summary = false;
});

// Parse command line arguments
parser.parse(ARGV);

if(print_summary) {
puts("First non-switch argument is: " + first_arg);

// Output all files that was included.
puts("No of files to include: " + options.files.length);
for(var i = 0; i < options.files.length; i++) {
puts("File [" + (i + 1) + "]:" + options.files[i]);
}

// Is debug-mode enabled?
puts("Debug mode is set to: " + options.debug);

puts("Number value is: " + options.number);
puts("Date value is: " + options.date);
}
}

0 comments on commit 3f185b0

Please sign in to comment.