Skip to content

Commit 9530d5b

Browse files
mahenzonreynolek
andauthored
pass extra options to httpsnippet (pass through to the target) (#222)
Co-authored-by: Eric Reynolds <eric.reynolds@konghq.com>
1 parent d9d3052 commit 9530d5b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ npm install --save httpsnippet
2323

2424
```
2525
26-
Usage: httpsnippet [options] <file>
26+
Usage: httpsnippet [options] <files ...>
2727
2828
Options:
2929
@@ -32,6 +32,7 @@ npm install --save httpsnippet
3232
-t, --target <target> target output
3333
-c, --client [client] target client library
3434
-o, --output <directory> write output to directory
35+
-x, --extra [{"optionKey": "optionValue"}] provide extra options for the target/client
3536
3637
```
3738

@@ -63,6 +64,13 @@ snippets/
6364
└── endpoint-3.js
6465
```
6566

67+
provide extra options:
68+
69+
```shell
70+
httpsnippet example.json --target http --output ./snippets -x '{"autoHost": false, "autoContentLength": false}'
71+
```
72+
73+
6674
## API
6775

6876
### HTTPSnippet(source)

bin/httpsnippet

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ cmd
1717
.option('-t, --target <target>', 'target output')
1818
.option('-c, --client [client]', 'target client library')
1919
.option('-o, --output <directory>', 'write output to directory')
20+
.option('-x, --extra [{"optionKey": "optionValue"}]', 'provide extra options for the target/client')
2021
.parse(process.argv)
2122

2223
if (!cmd.args.length || !cmd.target) {
2324
cmd.help()
2425
}
2526

27+
let extraOptions
28+
if (cmd.extra) {
29+
try {
30+
extraOptions = JSON.parse(cmd.extra)
31+
} catch (e) {
32+
console.error('%s failed to parse options %s (should be JSON)', chalk.red('✖'), chalk.cyan.bold(cmd.extra))
33+
process.exit()
34+
}
35+
}
36+
2637
let dir
2738
if (cmd.output) {
2839
dir = path.resolve(cmd.output)
@@ -53,7 +64,7 @@ cmd.args.forEach(function (fileName) {
5364
})
5465

5566
.then(function (snippet) {
56-
return snippet.convert(cmd.target, cmd.client)
67+
return snippet.convert(cmd.target, cmd.client, extraOptions)
5768
})
5869

5970
.then(function (output) {

0 commit comments

Comments
 (0)