Skip to content

Commit

Permalink
pass extra options to httpsnippet (pass through to the target) (#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Reynolds <[email protected]>
  • Loading branch information
mahenzon and reynolek authored Sep 3, 2021
1 parent d9d3052 commit 9530d5b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npm install --save httpsnippet

```
Usage: httpsnippet [options] <file>
Usage: httpsnippet [options] <files ...>
Options:
Expand All @@ -32,6 +32,7 @@ npm install --save httpsnippet
-t, --target <target> target output
-c, --client [client] target client library
-o, --output <directory> write output to directory
-x, --extra [{"optionKey": "optionValue"}] provide extra options for the target/client
```

Expand Down Expand Up @@ -63,6 +64,13 @@ snippets/
└── endpoint-3.js
```

provide extra options:

```shell
httpsnippet example.json --target http --output ./snippets -x '{"autoHost": false, "autoContentLength": false}'
```


## API

### HTTPSnippet(source)
Expand Down
13 changes: 12 additions & 1 deletion bin/httpsnippet
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ cmd
.option('-t, --target <target>', 'target output')
.option('-c, --client [client]', 'target client library')
.option('-o, --output <directory>', 'write output to directory')
.option('-x, --extra [{"optionKey": "optionValue"}]', 'provide extra options for the target/client')
.parse(process.argv)

if (!cmd.args.length || !cmd.target) {
cmd.help()
}

let extraOptions
if (cmd.extra) {
try {
extraOptions = JSON.parse(cmd.extra)
} catch (e) {
console.error('%s failed to parse options %s (should be JSON)', chalk.red('✖'), chalk.cyan.bold(cmd.extra))
process.exit()
}
}

let dir
if (cmd.output) {
dir = path.resolve(cmd.output)
Expand Down Expand Up @@ -53,7 +64,7 @@ cmd.args.forEach(function (fileName) {
})

.then(function (snippet) {
return snippet.convert(cmd.target, cmd.client)
return snippet.convert(cmd.target, cmd.client, extraOptions)
})

.then(function (output) {
Expand Down

0 comments on commit 9530d5b

Please sign in to comment.