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 bd692e1
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 5 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
6 changes: 4 additions & 2 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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"jpg"
],
"dependencies": {
"arrify": "^3.0.0",
"capture-website": "^3.0.0",
"get-stdin": "^9.0.0",
"meow": "^10.1.3",
Expand Down
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 bd692e1

Please sign in to comment.