-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added arguments to library call
- Loading branch information
Showing
7 changed files
with
130 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
# judge-d | ||
# Judge-d | ||
|
||
Judge-d is a JS CLI tool for publishing contracts using [judge-d](https://github.com/HLTech/judge-d) API. | ||
|
||
## Install | ||
|
||
```sh | ||
$ npm i judge-d -g | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
$ judge-d publish --help | ||
``` | ||
|
||
Help output: | ||
|
||
``` | ||
Publish contracts | ||
Options: | ||
--version Show version number [boolean] | ||
--help Show help [boolean] | ||
--url Url to judge-d instance [string] [required] | ||
--pactsDir Path to directory with pacts [string] [required] | ||
--serviceName Service name [string] [required] | ||
--serviceVersion Service version [string] [required] | ||
``` |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env/node | ||
#!/usr/bin/env node | ||
require('../lib/index.js').run(process); |
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { defineArgs } from './utils/define-args'; | ||
|
||
export function run(process: NodeJS.Process) { | ||
console.log(process.argv.slice(2)); | ||
const argv = defineArgs(process.argv.slice(2)); | ||
console.log(argv); | ||
} |
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,39 @@ | ||
import yargs from 'yargs'; | ||
|
||
interface CliArguments { | ||
url: string; | ||
pactsDir: string; | ||
serviceName: string; | ||
serviceVersion: string; | ||
} | ||
|
||
export function defineArgs(cliArgs: string[]): CliArguments { | ||
return yargs(cliArgs) | ||
.command<CliArguments>('publish', 'Publish contracts', (yargs) => { | ||
yargs.options({ | ||
url: { | ||
type: 'string', | ||
demandOption: true, | ||
describe: 'Url to judge-d instance', | ||
}, | ||
pactsDir: { | ||
type: 'string', | ||
demandOption: true, | ||
describe: 'Path to directory with pacts', | ||
}, | ||
serviceName: { | ||
type: 'string', | ||
demandOption: true, | ||
describe: 'Service name', | ||
}, | ||
serviceVersion: { | ||
type: 'string', | ||
demandOption: true, | ||
describe: 'Service version', | ||
}, | ||
}); | ||
}) | ||
.strict() | ||
.demandCommand(1, 'You need at least one command before moving on') | ||
.help().argv; | ||
} |
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,24 @@ | ||
import { defineArgs } from '../lib/utils/define-args'; | ||
|
||
describe('defineArgs', () => { | ||
test('returns correctly parsed process arguments', () => { | ||
const argv = defineArgs([ | ||
'publish', | ||
'--url', | ||
'judge-d.instance.com', | ||
'--pactsDir', | ||
'/pacts', | ||
'--serviceName', | ||
'example-service', | ||
'--serviceVersion', | ||
'1.0.0', | ||
]); | ||
|
||
expect(argv).toMatchObject({ | ||
url: 'judge-d.instance.com', | ||
pactsDir: '/pacts', | ||
serviceName: 'example-service', | ||
serviceVersion: '1.0.0', | ||
}); | ||
}); | ||
}); |