Skip to content

Commit

Permalink
Fix filename handling with multiple source URLs (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushantdhiman authored Dec 9, 2021
1 parent e6802a6 commit 61fd956
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -109,7 +109,10 @@ function get(args) {
}

function parse(args, globalOptions) {
return args.map(arg => {
const filename = arrify(globalOptions.filename);
delete globalOptions.filename;

return args.map((arg, index) => {
const options = {...globalOptions, ...arg};

arg = arg._;
@@ -123,6 +126,10 @@ function parse(args, globalOptions) {
options.header = parseHeaders(arrify(options.header).join('\n'));
}

if (filename[index]) {
options.filename = filename[index];
}

// Plural makes more sense for programmatic options
options.cookies = options.cookie;
options.headers = options.header;
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,16 @@ test('generate screenshots using keywords', async t => {
fs.unlinkSync('sindresorhus.com-320x568.png');
});

test('generate screenshots with multiple filename', async t => {
await execa.command('./cli.js [ https://google.com --filename=google ] [ https://sindresorhus.com --filename=sindre ]');

t.true(fs.existsSync('google.png'));
fs.unlinkSync('google.png');

t.true(fs.existsSync('sindre.png'));
fs.unlinkSync('sindre.png');
});

test('show help screen', async t => {
const {stdout} = await execa('./cli.js', ['--help']);
t.regex(stdout, /pageres <url>/);

0 comments on commit 61fd956

Please sign in to comment.