Skip to content

Commit

Permalink
Fix passing multiple —header flags
Browse files Browse the repository at this point in the history
Closes #43
  • Loading branch information
sindresorhus committed Apr 19, 2023
1 parent e9b5a7a commit 1fbac54
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
node-version:
- 18
- 16
- 14
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
12 changes: 8 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import process from 'node:process';
import meow from 'meow';
import captureWebsite from 'capture-website';
import arrify from 'arrify';
import splitOnFirst from 'split-on-first';
import getStdin from 'get-stdin';

Expand Down Expand Up @@ -166,6 +165,7 @@ const cli = meow(`
},
header: {
type: 'string',
isMultiple: true,
},
userAgent: {
type: 'string',
Expand Down Expand Up @@ -222,11 +222,13 @@ if (options.clip) {
}

options.headers = {};
for (const header of arrify(options.header)) {
for (const header of options.header) {
const [key, value] = header.split(':');
options.headers[key.trim()] = value.trim();
}

delete options.header;

if (options.authentication) {
const [username, password] = splitOnFirst(options.authentication, ':');
options.authentication = {username, password};
Expand Down Expand Up @@ -256,7 +258,7 @@ if (options.inset) {

options.isJavaScriptEnabled = options.javascript;

(async () => {
async function main() {
const {
internalPrintFlags,
listDevices,
Expand Down Expand Up @@ -288,4 +290,6 @@ options.isJavaScriptEnabled = options.javascript;
} else {
process.stdout.write(await captureWebsite.buffer(input, options));
}
})();
}

await main();
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@
"jpg"
],
"dependencies": {
"arrify": "^3.0.0",
"capture-website": "^3.0.0",
"capture-website": "^3.2.0",
"get-stdin": "^9.0.0",
"meow": "^10.1.3",
"meow": "^11.0.0",
"split-on-first": "^3.0.0"
},
"devDependencies": {
"ava": "^4.3.1",
"ava": "^5.2.0",
"create-test-server": "^3.0.1",
"execa": "^6.1.0",
"file-type": "^17.1.6",
"xo": "^0.51.0"
"execa": "^7.1.1",
"file-type": "^18.2.1",
"xo": "^0.54.1"
}
}
1 change: 0 additions & 1 deletion test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Generated by [AVA](https://avajs.dev).
element: '.main-content',
emulateDevice: 'iPhone X',
fullPage: false,
header: 'x-powered-by: capture-website-cli',
headers: {
'x-powered-by': 'capture-website-cli',
},
Expand Down
Binary file modified test.js.snap
Binary file not shown.

0 comments on commit 1fbac54

Please sign in to comment.