From a2a0fb4423fd9923c189707eef1526d574356afa Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 2 Nov 2019 10:25:47 -0500 Subject: [PATCH] fix: move completion into main, remove weird exit from arg parsing --- src/config/args.ts | 10 +--------- src/index.ts | 6 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/config/args.ts b/src/config/args.ts index 55c83fc..bd16387 100644 --- a/src/config/args.ts +++ b/src/config/args.ts @@ -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): 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, diff --git a/src/index.ts b/src/index.ts index b3616b1..b9f43a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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): Promise { 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);