Skip to content

Commit

Permalink
feat(main): wire up sync command stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Aug 12, 2020
1 parent 8dd63f7 commit d510a3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/config/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { usage } from 'yargs';

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

export enum Commands {
UNKNOWN = 'unknown',
ISSUES = 'sync-issues',
LABELS = 'sync-labels',
}

interface Parser<TData> {
parse(args: Array<string>): TData;
}

interface ParsedArgs {
export interface ParsedArgs {
remote: string;
}

Expand All @@ -16,14 +22,14 @@ export function createParser(modeset: Modeback): Parser<ParsedArgs> {
/* eslint-disable-next-line sonarjs/prefer-immediate-return */
const parser = usage(`Usage: ${VERSION_INFO.package.name} <mode> [options]`)
.command({
command: 'sync-issues',
describe: '',
handler: () => modeset('sync-issues'),
command: Commands.ISSUES,
describe: 'sync issue labels',
handler: () => modeset(Commands.ISSUES),
})
.command({
command: 'sync-labels',
describe: '',
handler: () => modeset('sync-labels'),
command: Commands.LABELS,
describe: 'sync project labels',
handler: () => modeset(Commands.LABELS),
})
.options({
remote: {
Expand Down
31 changes: 26 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createParser } from './config/args';
import { Commands, createParser } from './config/args';
import { GithubRemote } from './remote/github';
import { syncIssues, syncLabels, SyncOptions } from './sync';

export { FlagLabel, StateLabel } from './labels';
export { Remote, RemoteOptions } from './remote';
Expand All @@ -8,10 +10,11 @@ export { resolveLabels } from './resolve';
export { syncIssues, syncLabels } from './sync';

const SLICE_ARGS = 2;

export async function main(argv: Array<string>): Promise<number> {
// get arguments
let mode = '';
const parser = createParser((argMode) => mode = argMode);
let mode = Commands.UNKNOWN as Commands;
const parser = createParser((argMode) => mode = argMode as Commands);
const args = parser.parse(argv.slice(SLICE_ARGS));

/* eslint-disable no-console */
Expand All @@ -23,8 +26,26 @@ export async function main(argv: Array<string>): Promise<number> {
// create remote

// mode switch
// - sync labels
// - sync issues
const options: SyncOptions = {
config: {
colors: [],
flags: [],
remotes: [],
states: [],
},
project: '',
remote: new GithubRemote(),
};
switch (mode) {
case Commands.ISSUES:
await syncIssues(options);
break;
case Commands.LABELS:
await syncLabels(options);
break;
default:
console.log('unknown command');
}

return 0;
}

0 comments on commit d510a3a

Please sign in to comment.