-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #904 from macbre/decamelize-options
CLI - make sure options are not "camelCased" but "have-dashes" instead
- Loading branch information
Showing
5 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const decamelize = require("decamelize"); | ||
|
||
function decamelizeOptions(options) { | ||
// decamelize option names as returned by commander (see issue #863) | ||
let decamelized = {}; | ||
|
||
for (const [key, value] of Object.entries(options)) { | ||
decamelized[decamelize(key, { separator: "-" })] = value; | ||
} | ||
|
||
return decamelized; | ||
} | ||
|
||
module.exports = { | ||
decamelizeOptions, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Integration tests using server-start.sh script | ||
*/ | ||
const vows = require("vows"), | ||
assert = require("assert"), | ||
{ decamelizeOptions } = require("../bin/utils"); | ||
|
||
vows | ||
.describe("bin utils") | ||
.addBatch({ | ||
decamelizeOptions: { | ||
topic: function () { | ||
return decamelizeOptions({ | ||
url: "http://foo.com", | ||
userAgent: "foo/bar", | ||
}); | ||
}, | ||
"should decamelize options": function (opts) { | ||
assert.deepStrictEqual(opts, { | ||
url: "http://foo.com", | ||
"user-agent": "foo/bar", | ||
}); | ||
}, | ||
}, | ||
}) | ||
.export(module); |