Skip to content

Commit

Permalink
Add support for flags inside sub arguments
Browse files Browse the repository at this point in the history
Fixes #80.
  • Loading branch information
kevva committed Aug 16, 2014
1 parent f92b671 commit ac750d4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
46 changes: 23 additions & 23 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var _ = require('lodash');
var eachAsync = require('each-async');
var multiline = require('multiline');
var nopt = require('nopt');
var updateNotifier = require('update-notifier');
var stdin = require('get-stdin');
var subarg = require('subarg');
Expand All @@ -12,27 +11,26 @@ var logSymbols = require('log-symbols');
var pkg = require('./package.json');
var Pageres = require('./');

var options = nopt({
help: Boolean,
version: Boolean,
crop: Boolean,
delay: Number,
cookie: Array
}, {
h: '--help',
v: '--version',
c: '--crop',
d: '--delay'
var options = subarg(process.argv.slice(2), {
boolean: ['crop', 'help', 'version'],
default: { delay: 0 },
alias: {
c: 'crop',
d: 'delay',
h: 'help',
v: 'version'
}
});

var args = subarg(options.argv.remain)._;
var args = options._;
delete options._;

function showHelp() {
console.log(multiline(function () {/*
Capture screenshots of websites in various resolutions.
Specify urls and screen resolutions as arguments. Order doesn't matter. Group arguments with [ ]
Specify urls and screen resolutions as arguments. Order doesn't matter. Group arguments with [ ].
Options defined inside a group will override the outer ones.
Screenshots are saved in the current directory.
Usage
Expand All @@ -43,7 +41,7 @@ function showHelp() {
Example
pageres todomvc.com yeoman.io 1366x768 1600x900
pageres [ yeoman.io 1366x768 1600x900 ] [ todomvc.com 1024x768 480x320 ]
pageres [ yeoman.io 1366x768 1600x900 --crop ] [ todomvc.com 1024x768 480x320 ]
pageres --delay 3 1366x768 < urls.txt
pageres unicorn.html 1366x768
cat screen-resolutions.txt | pageres todomvc.com yeoman.io
Expand All @@ -64,7 +62,7 @@ function generate(args, opts) {
.dest(process.cwd());

args.forEach(function (arg) {
pageres.src(arg.url, arg.sizes);
pageres.src(arg.url, arg.sizes, arg.options);
});

pageres.run(function (err) {
Expand Down Expand Up @@ -100,7 +98,7 @@ function get(args, options, cb) {
}

arg.url.forEach(function (el) {
ret.push({ url: el, sizes: arg.sizes });
ret.push({ url: el, sizes: arg.sizes, options: arg.options });
});

next();
Expand All @@ -117,26 +115,28 @@ function parse(args) {
var ret = [];

args.forEach(function (arg) {
var options = arg;
arg = arg._;
delete options._;

var url = _.uniq(arg.filter(/./.test, /\.|localhost/));
var sizes = _.uniq(arg.filter(/./.test, /^\d{3,4}x\d{3,4}$/i));
var keywords = _.difference(arg, url.concat(sizes));

ret.push({ url: url, sizes: sizes, keywords: keywords });
ret.push({ url: url, sizes: sizes, keywords: keywords, options: options });
});

return ret;
}

function init(args, options) {
if (options.help || args.length === 0) {
showHelp();
if (options.version) {
console.log(require('./package').version);
return;
}

if (options.version) {
console.log(require('./package').version);
if (options.help || args.length === 0) {
showHelp();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Pageres.prototype.run = function (cb) {
}

eachAsync(this.src(), function (src, i, next) {
var options = assign(self.options, src.options || {});
var options = assign({}, self.options, src.options || {});
var sizes = _.uniq(src.sizes.filter(/./.test, /^\d{3,4}x\d{3,4}$/i));
var keywords = _.difference(src.sizes, sizes);

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"memoize-async": "^1.0.1",
"mkdirp": "^0.5.0",
"multiline": "^0.3.0",
"nopt": "^3.0.0",
"object-assign": "^1.0.0",
"parse-cookie-phantomjs": "^1.0.0",
"phantomjs": "1.9.2-6",
Expand Down
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ $ npm install --global pageres
```
$ pageres --help
Specify urls and screen resolutions as arguments. Order doesn't matter. Group arguments with [ ]
Specify urls and screen resolutions as arguments. Order doesn't matter. Group arguments with [ ].
Options defined inside a group will override the outer ones.
Screenshots are saved in the current directory.
Usage
Expand All @@ -38,7 +39,7 @@ Usage
Example
pageres todomvc.com yeoman.io 1366x768 1600x900
pageres [ yeoman.io 1366x768 1600x900 ] [ todomvc.com 1024x768 480x320 ]
pageres [ yeoman.io 1366x768 1600x900 --crop ] [ todomvc.com 1024x768 480x320 ]
pageres --delay 3 1366x768 < urls.txt
pageres unicorn.html 1366x768
cat screen-resolutions.txt | pageres todomvc.com yeoman.io
Expand All @@ -50,7 +51,7 @@ Options
<url> can also be a local file path.
You can also pipe in a newline separated list of urls and screen resolutions which will get merged with the arguments. If no screen resolutions are specified it will fall back to the ten most popular ones according to w3counter.
You can also pipe in a newline separated list of urls and screen resolutions which will get merged with the arguments.
```


Expand Down

0 comments on commit ac750d4

Please sign in to comment.