feat(main): wire up sync command stubs
This commit is contained in:
parent
8dd63f770a
commit
d510a3afb3
|
@ -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: {
|
||||
|
|
31
src/main.ts
31
src/main.ts
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue