added missing exit code (when errornous)
Showing
13 changed files
with
48 additions
and
24 deletions
... | @@ -6,7 +6,9 @@ casper.cli.drop "cli" | ... | @@ -6,7 +6,9 @@ casper.cli.drop "cli" |
6 | casper.cli.drop "casper-path" | 6 | casper.cli.drop "casper-path" |
7 | 7 | ||
8 | if casper.cli.args.length is 0 and Object.keys(casper.cli.options).length is 0 | 8 | if casper.cli.args.length is 0 and Object.keys(casper.cli.options).length is 0 |
9 | casper.echo("Pass some args and options to see how they are handled by CasperJS").exit() | 9 | casper |
10 | .echo("Pass some args and options to see how they are handled by CasperJS") | ||
11 | .exit(1) | ||
10 | 12 | ||
11 | casper.echo "Casper CLI passed args:" | 13 | casper.echo "Casper CLI passed args:" |
12 | dump casper.cli.args | 14 | dump casper.cli.args | ... | ... |
... | @@ -6,7 +6,10 @@ casper.cli.drop("cli"); | ... | @@ -6,7 +6,10 @@ casper.cli.drop("cli"); |
6 | casper.cli.drop("casper-path"); | 6 | casper.cli.drop("casper-path"); |
7 | 7 | ||
8 | if (casper.cli.args.length === 0 && Object.keys(casper.cli.options).length === 0) { | 8 | if (casper.cli.args.length === 0 && Object.keys(casper.cli.options).length === 0) { |
9 | casper.echo("Pass some args and options to see how they are handled by CasperJS").exit(); | 9 | casper |
10 | .echo("Pass some args and options to see how they are handled by CasperJS") | ||
11 | .exit(1) | ||
12 | ; | ||
10 | } | 13 | } |
11 | 14 | ||
12 | casper.echo("Casper CLI passed args:"); | 15 | casper.echo("Casper CLI passed args:"); | ... | ... |
1 | """ A basic custom logging implementation. The idea is to (extremely) verbosely | 1 | ### |
2 | log every received resource. | 2 | A basic custom logging implementation. The idea is to (extremely) verbosely |
3 | """ | 3 | log every received resource. |
4 | ### | ||
4 | 5 | ||
5 | casper = require('casper').create | 6 | casper = require('casper').create |
6 | # Every time a resource is received, a new log entry is added to the stack | 7 | # Every time a resource is received, a new log entry is added to the stack | ... | ... |
... | @@ -20,8 +20,9 @@ casper.fetchScore = -> | ... | @@ -20,8 +20,9 @@ casper.fetchScore = -> |
20 | terms = casper.cli.args # terms are passed through command-line arguments | 20 | terms = casper.cli.args # terms are passed through command-line arguments |
21 | 21 | ||
22 | if terms.length < 3 | 22 | if terms.length < 3 |
23 | casper.echo 'Usage: casperjs googlematch.js term1, term2 [, term3]...' | 23 | casper |
24 | casper.exit() | 24 | .echo 'Usage: casperjs googlematch.js term1, term2 [, term3]...' |
25 | .exit(1) | ||
25 | 26 | ||
26 | scores = [] | 27 | scores = [] |
27 | 28 | ... | ... |
... | @@ -21,7 +21,10 @@ casper.fetchScore = function() { | ... | @@ -21,7 +21,10 @@ casper.fetchScore = function() { |
21 | }; | 21 | }; |
22 | 22 | ||
23 | if (terms.length < 2) { | 23 | if (terms.length < 2) { |
24 | casper.echo('Usage: casperjs googlematch.js term1, term2 [, term3]...').exit(); | 24 | casper |
25 | .echo('Usage: casperjs googlematch.js term1, term2 [, term3]...') | ||
26 | .exit(1) | ||
27 | ; | ||
25 | } | 28 | } |
26 | 29 | ||
27 | casper.echo('Let the match begin!'); | 30 | casper.echo('Let the match begin!'); | ... | ... |
... | @@ -8,8 +8,9 @@ casper = require('casper').create() | ... | @@ -8,8 +8,9 @@ casper = require('casper').create() |
8 | currentPage = 1 | 8 | currentPage = 1 |
9 | 9 | ||
10 | if casper.cli.args.length == 0 | 10 | if casper.cli.args.length == 0 |
11 | casper.echo "usage: $ casperjs my search terms" | 11 | casper |
12 | casper.exit() | 12 | .echo "usage: $ casperjs my search terms" |
13 | .exit(1) | ||
13 | 14 | ||
14 | processPage = -> | 15 | processPage = -> |
15 | @echo "capturing page #{currentPage}" | 16 | @echo "capturing page #{currentPage}" | ... | ... |
... | @@ -4,8 +4,10 @@ casper = require('casper').create(); | ... | @@ -4,8 +4,10 @@ casper = require('casper').create(); |
4 | currentPage = 1; | 4 | currentPage = 1; |
5 | 5 | ||
6 | if (casper.cli.args.length === 0) { | 6 | if (casper.cli.args.length === 0) { |
7 | casper.echo("usage: $ casperjs my search terms"); | 7 | casper |
8 | casper.exit(); | 8 | .echo("usage: $ casperjs my search terms") |
9 | .exit(1) | ||
10 | ; | ||
9 | } | 11 | } |
10 | 12 | ||
11 | processPage = function() { | 13 | processPage = function() { |
... | @@ -37,4 +39,4 @@ casper.start('http://google.fr/', function() { | ... | @@ -37,4 +39,4 @@ casper.start('http://google.fr/', function() { |
37 | 39 | ||
38 | casper.then(processPage); | 40 | casper.then(processPage); |
39 | 41 | ||
40 | casper.run(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
42 | casper.run(); | ... | ... |
... | @@ -3,8 +3,9 @@ url = casper.cli.get 0 | ... | @@ -3,8 +3,9 @@ url = casper.cli.get 0 |
3 | metas = [] | 3 | metas = [] |
4 | 4 | ||
5 | if not url | 5 | if not url |
6 | casper.echo "Usage: casperjs [url]" | 6 | casper |
7 | casper.exit() | 7 | .echo "Usage: casperjs [url]" |
8 | .exit(1) | ||
8 | 9 | ||
9 | casper.start url, -> | 10 | casper.start url, -> |
10 | metas = @evaluate -> | 11 | metas = @evaluate -> | ... | ... |
... | @@ -3,7 +3,10 @@ var casper = require("casper").create() | ... | @@ -3,7 +3,10 @@ var casper = require("casper").create() |
3 | , metas = []; | 3 | , metas = []; |
4 | 4 | ||
5 | if (!url) { | 5 | if (!url) { |
6 | casper.echo('Usage: casperjs [url]').exit(); | 6 | casper |
7 | .echo('Usage: casperjs [url]') | ||
8 | .exit(1) | ||
9 | ; | ||
7 | } | 10 | } |
8 | 11 | ||
9 | casper.start(url, function() { | 12 | casper.start(url, function() { | ... | ... |
... | @@ -11,8 +11,9 @@ twitterAccount = casper.cli.get 0 | ... | @@ -11,8 +11,9 @@ twitterAccount = casper.cli.get 0 |
11 | filename = casper.cli.get 1 | 11 | filename = casper.cli.get 1 |
12 | 12 | ||
13 | if not twitterAccount or not filename or not /\.(png|jpg|pdf)$/i.test filename | 13 | if not twitterAccount or not filename or not /\.(png|jpg|pdf)$/i.test filename |
14 | casper.echo "Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>" | 14 | casper |
15 | casper.exit() | 15 | .echo "Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>" |
16 | .exit(1) | ||
16 | 17 | ||
17 | casper.start "https://twitter.com/#!/#{twitterAccount}", -> | 18 | casper.start "https://twitter.com/#!/#{twitterAccount}", -> |
18 | capture = -> | 19 | capture = -> | ... | ... |
... | @@ -14,8 +14,10 @@ var twitterAccount = casper.cli.get(0); | ... | @@ -14,8 +14,10 @@ var twitterAccount = casper.cli.get(0); |
14 | var filename = casper.cli.get(1); | 14 | var filename = casper.cli.get(1); |
15 | 15 | ||
16 | if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) { | 16 | if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) { |
17 | casper.echo("Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"); | 17 | casper |
18 | casper.exit(); | 18 | .echo("Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>") |
19 | .exit(1) | ||
20 | ; | ||
19 | } | 21 | } |
20 | 22 | ||
21 | casper.start('https://twitter.com/#!/' + twitterAccount, function() { | 23 | casper.start('https://twitter.com/#!/' + twitterAccount, function() { | ... | ... |
... | @@ -21,8 +21,9 @@ casper = require('casper').create | ... | @@ -21,8 +21,9 @@ casper = require('casper').create |
21 | 21 | ||
22 | timeout = ~~casper.cli.get 0 | 22 | timeout = ~~casper.cli.get 0 |
23 | if timeout < 1 | 23 | if timeout < 1 |
24 | casper.echo "You must pass a valid timeout value" | 24 | casper |
25 | casper.exit() | 25 | .echo "You must pass a valid timeout value" |
26 | .exit(1) | ||
26 | 27 | ||
27 | casper.echo "Will google.com load in less than #{timeout}ms?" | 28 | casper.echo "Will google.com load in less than #{timeout}ms?" |
28 | casper.options.timeout = timeout | 29 | casper.options.timeout = timeout | ... | ... |
... | @@ -22,7 +22,10 @@ var casper = require('casper').create({ | ... | @@ -22,7 +22,10 @@ var casper = require('casper').create({ |
22 | 22 | ||
23 | var timeout = ~~casper.cli.get(0); | 23 | var timeout = ~~casper.cli.get(0); |
24 | if (timeout < 1) { | 24 | if (timeout < 1) { |
25 | casper.echo('You must pass a valid timeout value').exit(); | 25 | casper |
26 | .echo('You must pass a valid timeout value') | ||
27 | .exit(1) | ||
28 | ; | ||
26 | } | 29 | } |
27 | casper.echo('Will google.com load in less than ' + timeout + 'ms?'); | 30 | casper.echo('Will google.com load in less than ' + timeout + 'ms?'); |
28 | casper.options.timeout = timeout; | 31 | casper.options.timeout = timeout; |
... | @@ -31,4 +34,4 @@ casper.start('http://www.google.com/', function(self) { | ... | @@ -31,4 +34,4 @@ casper.start('http://www.google.com/', function(self) { |
31 | self.echo('YES!', 'GREEN_BAR').exit(); | 34 | self.echo('YES!', 'GREEN_BAR').exit(); |
32 | }); | 35 | }); |
33 | 36 | ||
34 | casper.run(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
37 | casper.run(); | ... | ... |
-
Please register or sign in to post a comment