From 61fd9566825082f1da1a19b9d98c53fb799945d5 Mon Sep 17 00:00:00 2001 From: Sushant Date: Thu, 9 Dec 2021 23:46:53 +0530 Subject: [PATCH] Fix filename handling with multiple source URLs (#9) --- cli.js | 9 ++++++++- test/test.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index 2cef3f6..8738f9e 100755 --- a/cli.js +++ b/cli.js @@ -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; diff --git a/test/test.js b/test/test.js index 14c3dfd..67f7d13 100644 --- a/test/test.js +++ b/test/test.js @@ -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 /);