1
0
Fork 0

fix: move completion into main, remove weird exit from arg parsing

This commit is contained in:
ssube 2019-11-02 10:25:47 -05:00 committed by Sean Sube
parent b99431b368
commit a2a0fb4423
2 changed files with 7 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import { Options, showCompletionScript, usage } from 'yargs';
import { Options, usage } from 'yargs';
import { RuleSelector, RuleSources } from '../rule';
import { VERSION_INFO } from '../version';
@ -158,14 +158,6 @@ export function parseArgs(argv: Array<string>): ParseResults {
// @TODO: this should not need a cast but argv's type only has the last option (include-tag)
// @tslint:disable-next-line:no-any
const args = parser.argv as any;
// this should not need a cast either, but something here allows TS to narrow MODE into
// MODE.check, which is much _too_ specific
if (mode as MODE === MODE.complete) {
showCompletionScript();
process.exit(0);
}
return {
args,
mode,

View File

@ -1,4 +1,5 @@
import { createLogger } from 'bunyan';
import { showCompletionScript } from 'yargs';
import { loadConfig } from './config';
import { CONFIG_ARGS_NAME, CONFIG_ARGS_PATH, MODE, parseArgs, VALID_MODES } from './config/args';
@ -14,6 +15,11 @@ const STATUS_MAX = 255;
export async function main(argv: Array<string>): Promise<number> {
const { args, mode } = parseArgs(argv);
if (mode === MODE.complete) {
showCompletionScript();
return STATUS_SUCCESS;
}
const config = await loadConfig(args[CONFIG_ARGS_NAME], ...args[CONFIG_ARGS_PATH]);
const logger = createLogger(config.data.logger);