feat(main): capture command as mode
This commit is contained in:
parent
1f641fc7ad
commit
8dd63f770a
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue