Skip to content

Commit

Permalink
feat: add main function, arg parsing for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Aug 12, 2020
1 parent 0d34158 commit 1f641fc
Show file tree
Hide file tree
Showing 30 changed files with 343 additions and 19 deletions.
3 changes: 0 additions & 3 deletions config/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ const bundle = {
commonjs({
namedExports,
}),
polyfills({
buffer: false,
}),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
Expand Down
5 changes: 5 additions & 0 deletions docs/api/cautious-journey.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
| [FlagLabel](./cautious-journey.flaglabel.md) | Individual labels: the equivalent of a checkbox. |
| [Remote](./cautious-journey.remote.md) | Basic functions which every remote API must provide. |
| [RemoteOptions](./cautious-journey.remoteoptions.md) | |
| [ResolveInput](./cautious-journey.resolveinput.md) | Collected inputs for a resolver run. |
| [ResolveResult](./cautious-journey.resolveresult.md) | Collected results from a resolver run. |
| [StateChange](./cautious-journey.statechange.md) | The transition between two state values. |
| [StateLabel](./cautious-journey.statelabel.md) | Grouped labels: the equivalent of a radio group. |
| [StateValue](./cautious-journey.statevalue.md) | One of many values for a particular state. |
| [SyncOptions](./cautious-journey.syncoptions.md) | |

11 changes: 11 additions & 0 deletions docs/api/cautious-journey.resolveinput.flags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md) &gt; [flags](./cautious-journey.resolveinput.flags.md)

## ResolveInput.flags property

<b>Signature:</b>

```typescript
flags: Array<FlagLabel>;
```
11 changes: 11 additions & 0 deletions docs/api/cautious-journey.resolveinput.labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md) &gt; [labels](./cautious-journey.resolveinput.labels.md)

## ResolveInput.labels property

<b>Signature:</b>

```typescript
labels: Array<string>;
```
22 changes: 22 additions & 0 deletions docs/api/cautious-journey.resolveinput.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md)

## ResolveInput interface

Collected inputs for a resolver run.

<b>Signature:</b>

```typescript
export interface ResolveInput
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [flags](./cautious-journey.resolveinput.flags.md) | Array&lt;[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->&gt; | |
| [labels](./cautious-journey.resolveinput.labels.md) | Array&lt;string&gt; | |
| [states](./cautious-journey.resolveinput.states.md) | Array&lt;[StateLabel](./cautious-journey.statelabel.md)<!-- -->&gt; | |

11 changes: 11 additions & 0 deletions docs/api/cautious-journey.resolveinput.states.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md) &gt; [states](./cautious-journey.resolveinput.states.md)

## ResolveInput.states property

<b>Signature:</b>

```typescript
states: Array<StateLabel>;
```
4 changes: 2 additions & 2 deletions docs/api/cautious-journey.resolvelabels.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export declare function resolveLabels(options: ResolveInput): ResolveResult;

| Parameter | Type | Description |
| --- | --- | --- |
| options | ResolveInput | |
| options | [ResolveInput](./cautious-journey.resolveinput.md) | |

<b>Returns:</b>

ResolveResult
[ResolveResult](./cautious-journey.resolveresult.md)

11 changes: 11 additions & 0 deletions docs/api/cautious-journey.resolveresult.changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md) &gt; [changes](./cautious-journey.resolveresult.changes.md)

## ResolveResult.changes property

<b>Signature:</b>

```typescript
changes: Array<ChangeRecord>;
```
11 changes: 11 additions & 0 deletions docs/api/cautious-journey.resolveresult.errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md) &gt; [errors](./cautious-journey.resolveresult.errors.md)

## ResolveResult.errors property

<b>Signature:</b>

```typescript
errors: Array<unknown>;
```
11 changes: 11 additions & 0 deletions docs/api/cautious-journey.resolveresult.labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md) &gt; [labels](./cautious-journey.resolveresult.labels.md)

## ResolveResult.labels property

<b>Signature:</b>

```typescript
labels: Array<string>;
```
22 changes: 22 additions & 0 deletions docs/api/cautious-journey.resolveresult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md)

## ResolveResult interface

Collected results from a resolver run.

<b>Signature:</b>

```typescript
export interface ResolveResult
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [changes](./cautious-journey.resolveresult.changes.md) | Array&lt;ChangeRecord&gt; | |
| [errors](./cautious-journey.resolveresult.errors.md) | Array&lt;unknown&gt; | |
| [labels](./cautious-journey.resolveresult.labels.md) | Array&lt;string&gt; | |

13 changes: 13 additions & 0 deletions docs/api/cautious-journey.statechange.matches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [StateChange](./cautious-journey.statechange.md) &gt; [matches](./cautious-journey.statechange.matches.md)

## StateChange.matches property

Required labels for this state change to occur.

<b>Signature:</b>

```typescript
matches: Array<LabelRef>;
```
21 changes: 21 additions & 0 deletions docs/api/cautious-journey.statechange.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [StateChange](./cautious-journey.statechange.md)

## StateChange interface

The transition between two state values.

<b>Signature:</b>

```typescript
export interface StateChange extends LabelSet
```
<b>Extends:</b> LabelSet
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [matches](./cautious-journey.statechange.matches.md) | Array&lt;LabelRef&gt; | Required labels for this state change to occur. |
2 changes: 1 addition & 1 deletion docs/api/cautious-journey.statelabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface StateLabel extends BaseLabel, LabelSet
| Property | Type | Description |
| --- | --- | --- |
| [values](./cautious-journey.statelabel.values.md) | Array&lt;StateValue&gt; | Values for this state. |
| [values](./cautious-journey.statelabel.values.md) | Array&lt;[StateValue](./cautious-journey.statevalue.md)<!-- -->&gt; | Values for this state. |
13 changes: 13 additions & 0 deletions docs/api/cautious-journey.statevalue.becomes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [StateValue](./cautious-journey.statevalue.md) &gt; [becomes](./cautious-journey.statevalue.becomes.md)

## StateValue.becomes property

State changes that could occur to this value.

<b>Signature:</b>

```typescript
becomes: Array<StateChange>;
```
21 changes: 21 additions & 0 deletions docs/api/cautious-journey.statevalue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [StateValue](./cautious-journey.statevalue.md)

## StateValue interface

One of many values for a particular state.

<b>Signature:</b>

```typescript
export interface StateValue extends BaseLabel
```
<b>Extends:</b> BaseLabel
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [becomes](./cautious-journey.statevalue.becomes.md) | Array&lt;[StateChange](./cautious-journey.statechange.md)<!-- -->&gt; | State changes that could occur to this value. |
2 changes: 1 addition & 1 deletion docs/api/cautious-journey.syncissues.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare function syncIssues(options: SyncOptions): Promise<unknown>;

| Parameter | Type | Description |
| --- | --- | --- |
| options | SyncOptions | |
| options | [SyncOptions](./cautious-journey.syncoptions.md) | |

<b>Returns:</b>

Expand Down
2 changes: 1 addition & 1 deletion docs/api/cautious-journey.synclabels.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare function syncLabels(options: SyncOptions): Promise<unknown>;

| Parameter | Type | Description |
| --- | --- | --- |
| options | SyncOptions | |
| options | [SyncOptions](./cautious-journey.syncoptions.md) | |

<b>Returns:</b>

Expand Down
11 changes: 11 additions & 0 deletions docs/api/cautious-journey.syncoptions.config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [config](./cautious-journey.syncoptions.config.md)

## SyncOptions.config property

<b>Signature:</b>

```typescript
config: ConfigData;
```
20 changes: 20 additions & 0 deletions docs/api/cautious-journey.syncoptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md)

## SyncOptions interface

<b>Signature:</b>

```typescript
export interface SyncOptions
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [config](./cautious-journey.syncoptions.config.md) | ConfigData | |
| [project](./cautious-journey.syncoptions.project.md) | string | |
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |

11 changes: 11 additions & 0 deletions docs/api/cautious-journey.syncoptions.project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [project](./cautious-journey.syncoptions.project.md)

## SyncOptions.project property

<b>Signature:</b>

```typescript
project: string;
```
11 changes: 11 additions & 0 deletions docs/api/cautious-journey.syncoptions.remote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [remote](./cautious-journey.syncoptions.remote.md)

## SyncOptions.remote property

<b>Signature:</b>

```typescript
remote: Remote;
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/react-dom": "^16.9.8",
"@types/sinon-chai": "3.2.4",
"@types/source-map-support": "0.5.2",
"@types/yargs-parser": "^15.0.0",
"@types/yargs": "^15.0.5",
"@typescript-eslint/eslint-plugin": "3.8.0",
"@typescript-eslint/eslint-plugin-tslint": "3.8.0",
"@typescript-eslint/parser": "3.8.0",
Expand Down Expand Up @@ -81,7 +81,7 @@
"tslint-microsoft-contrib": "6.2.0",
"tslint-sonarts": "1.9.0",
"typescript": "3.9.7",
"yargs-parser": "^18.1.3"
"yargs": "^15.4.1"
},
"husky": {
"hooks": {
Expand Down
26 changes: 26 additions & 0 deletions src/config/args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { usage } from 'yargs';

import { VERSION_INFO } from '../version';

export function createParser() {
let mode = '';

function handleMode(argi: string) {
mode = argi;
}

/* eslint-disable-next-line sonarjs/prefer-immediate-return */
const parser = usage(`Usage: ${VERSION_INFO.package.name} <mode> [options]`)
.command({
command: 'sync-issues',
describe: '',
handler: handleMode,
})
.command({
command: 'sync-labels',
describe: '',
handler: handleMode,
});

return parser;
}
4 changes: 2 additions & 2 deletions src/config.ts → src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FlagLabel, StateLabel } from './labels';
import { RemoteOptions } from './remote';
import { FlagLabel, StateLabel } from '../labels';
import { RemoteOptions } from '../remote';

/**
* Config data for the app, loaded from CLI or DOM.
Expand Down
19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
export { FlagLabel, StateLabel } from './labels';
import { main } from './main';

export { FlagLabel, StateChange, StateLabel, StateValue } from './labels';
export { Remote, RemoteOptions } from './remote';
export { GithubRemote } from './remote/github';
export { GitlabRemote } from './remote/gitlab';
export { resolveLabels } from './resolve';
export { syncIssues, syncLabels } from './sync';
export { ResolveInput, ResolveResult, resolveLabels } from './resolve';
export { syncIssues, syncLabels, SyncOptions } from './sync';

const STATUS_ERROR = 1;

/**
* This is the main entry-point to the program and the only file not included in the main bundle.
*/
main(process.argv).then((status) => process.exit(status)).catch((err: Error) => {
// eslint-disable-next-line no-console
console.error('uncaught error during main:', err);
process.exit(STATUS_ERROR);
});

0 comments on commit 1f641fc

Please sign in to comment.