1
0
Fork 0

feat(main): wire up sync command stubs

This commit is contained in:
ssube 2020-08-11 22:52:14 -05:00
parent 8dd63f770a
commit d510a3afb3
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 39 additions and 12 deletions

View File

@ -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;
}
@ -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: {

View File

@ -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';
@ -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 */
@ -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;
}