Skip to content

Commit

Permalink
feat: Added arguments to library call
Browse files Browse the repository at this point in the history
  • Loading branch information
pawfa committed Mar 10, 2021
1 parent 6a24f74 commit ff085d8
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 83 deletions.
31 changes: 30 additions & 1 deletion README.md
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]
```
2 changes: 1 addition & 1 deletion bin/judge-d.js
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);
106 changes: 27 additions & 79 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"main": "./lib/index.js",
"bin": {
"judge-d": "judge-d.js"
"judge-d": "./bin/judge-d.js"
},
"files": [
"bin",
Expand All @@ -32,6 +32,7 @@
"homepage": "https://github.com/HLTech/judge-d-js",
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/yargs": "^15.0.13",
"husky": "^5.1.3",
"jest": "^26.6.3",
"prettier": "^2.2.1",
Expand All @@ -42,5 +43,8 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"tag": "latest"
},
"dependencies": {
"yargs": "^15.4.1"
}
}
5 changes: 4 additions & 1 deletion src/index.ts
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);
}
39 changes: 39 additions & 0 deletions src/utils/define-args.ts
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;
}
24 changes: 24 additions & 0 deletions test/define-args.test.ts
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',
});
});
});

0 comments on commit ff085d8

Please sign in to comment.