Commit de6db3a4 de6db3a4c0bb481f9b99c0d288d66fb6cd626bfd by Nicolas Perriault

refs #28 - removed unused file

1 parent 4e7d7382
1 /**
2 * Phantom args parsing utilities.
3 *
4 */
5 (function(phantom) {
6 phantom.Casper.Cli = function() {
7 /**
8 * Extract current named parameters passed to the phantom script through
9 * the command line. Named arguments are of the form --foo=bar ou --foo
10 *
11 */
12 this.named = phantom.args.forEach(function(arg) {
13 if (arg.indexOf('--') === 0) {
14 var match = /--(.*)=(.*)\s?/i.exec(arg);
15 if (match) {
16 params[match[1]] = match[2];
17 } else {
18 var match2 = /--(.*)\s?/i.exec(arg);
19 if (match2) {
20 params[match2[1]] = true;
21 }
22 }
23 }
24 });
25
26 /**
27 * Checks that the specified named arguments have been passed to current
28 * phantom script. Dies on failure by default, but you can provide an
29 * onError callback for hooking on fail and do what you want.
30 *
31 */
32 this.requireNamedArgs = function(list, onError) {
33 var missing = [], params = phantom.extractNamedArgs();
34 for (var i = 0; i < list.length; i++) {
35 var name = list[i];
36 if (!params.hasOwnProperty(name)) {
37 missing.push(name);
38 }
39 }
40 if (missing.length > 0) {
41 if (typeof(onError) === "function") {
42 onError(missing);
43 } else {
44 var s = missing.length > 1 ? 'are' : 'is a';
45 console.log(JSON.stringify({
46 status: "error",
47 message: '"' + (missing.join('", "')) + '" ' + s + ' required named parameters.'
48 }, null, ' '));
49 phantom.exit(1);
50 }
51 }
52 };
53 };
54 })(phantom);