File tree Expand file tree Collapse file tree 2 files changed +35
-5
lines changed Expand file tree Collapse file tree 2 files changed +35
-5
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ import arg from 'arg' ;
1
3
import { overlayFiles } from './src/overlay.js'
2
4
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
+ }
8
34
Original file line number Diff line number Diff line change 3
3
"version" : " 1.0.0" ,
4
4
"description" : " " ,
5
5
"main" : " index.js" ,
6
+ "bin" : {
7
+ "overlayjs" : " ./index.js"
8
+ },
6
9
"scripts" : {
7
10
"test" : " node_modules/.bin/jest"
8
11
},
11
14
"license" : " Apache2" ,
12
15
"dependencies" : {
13
16
"@stoplight/yaml" : " ^4.2.3" ,
17
+ "arg" : " ^5.0.2" ,
14
18
"jsonpath" : " ^1.1.1" ,
15
19
"mergician" : " ^1.0.3" ,
16
20
"openapi-format" : " ^1.13.0"
You can’t perform that action at this time.
0 commit comments