1
0
Fork 0

feat(main): capture command as mode

This commit is contained in:
ssube 2020-08-11 22:40:21 -05:00
parent 1f641fc7ad
commit 8dd63f770a
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 24 additions and 10 deletions

View File

@ -2,24 +2,35 @@ import { usage } from 'yargs';
import { VERSION_INFO } from '../version';
export function createParser() {
let mode = '';
interface Parser<TData> {
parse(args: Array<string>): TData;
}
function handleMode(argi: string) {
mode = argi;
}
interface ParsedArgs {
remote: string;
}
type Modeback = (mode: string) => void;
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: handleMode,
handler: () => modeset('sync-issues'),
})
.command({
command: 'sync-labels',
describe: '',
handler: handleMode,
handler: () => modeset('sync-labels'),
})
.options({
remote: {
alias: ['r'],
demand: true,
type: 'string',
}
});
return parser;

View File

@ -7,12 +7,15 @@ export { GitlabRemote } from './remote/gitlab';
export { resolveLabels } from './resolve';
export { syncIssues, syncLabels } from './sync';
const SLICE_ARGS = 2;
export async function main(argv: Array<string>): Promise<number> {
// get arguments
const parser = createParser();
const args = parser.parse(argv.slice(0));
let mode = '';
const parser = createParser((argMode) => mode = argMode);
const args = parser.parse(argv.slice(SLICE_ARGS));
/* eslint-disable-next-line no-console */
/* eslint-disable no-console */
console.log('mode:', mode);
console.log('args:', args);
// load config