Skip to content

Commit d756525

Browse files
authored
Merge pull request #3 from lornajane/add-cli-wrapper
Add arg library, publish as overlayjs command
2 parents 6401805 + ea64363 commit d756525

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

index.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
#!/usr/bin/env node
2+
import arg from 'arg';
13
import {overlayFiles} from './src/overlay.js'
24

3-
// example: node index.js test/openapi/petstore.yaml test/overlays/overlay.yaml
4-
const openapiFile = process.argv[2]
5-
const overlayFile = process.argv[3]
6-
var spec = overlayFiles(openapiFile, overlayFile);
7-
console.log(spec);
5+
function showHelp() {
6+
console.log("Usage: overlayjs --openapi FILEPATH --overlay FILEPATH");
7+
console.log(" use --help to see this help");
8+
}
9+
10+
try {
11+
const args = arg({
12+
'--openapi': String,
13+
'--overlay': String,
14+
'--help': String
15+
});
16+
17+
if(args['--overlay'] && args['--openapi']) {
18+
const openapiFile = args['--openapi'];
19+
const overlayFile = args['--overlay'];
20+
var spec = overlayFiles(openapiFile, overlayFile);
21+
console.log(spec);
22+
} else {
23+
showHelp()
24+
}
25+
26+
} catch (err) {
27+
if (err.code === 'ARG_UNKNOWN_OPTION') {
28+
console.warn(err.message);
29+
showHelp()
30+
} else {
31+
throw err;
32+
}
33+
}
834

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6+
"bin": {
7+
"overlayjs": "./index.js"
8+
},
69
"scripts": {
710
"test": "node_modules/.bin/jest"
811
},
@@ -11,6 +14,7 @@
1114
"license": "Apache2",
1215
"dependencies": {
1316
"@stoplight/yaml": "^4.2.3",
17+
"arg": "^5.0.2",
1418
"jsonpath": "^1.1.1",
1519
"mergician": "^1.0.3",
1620
"openapi-format": "^1.13.0"

0 commit comments

Comments
 (0)