fix: move completion into main, remove weird exit from arg parsing
This commit is contained in:
parent
b99431b368
commit
a2a0fb4423
|
@ -1,4 +1,4 @@
|
||||||
import { Options, showCompletionScript, usage } from 'yargs';
|
import { Options, usage } from 'yargs';
|
||||||
|
|
||||||
import { RuleSelector, RuleSources } from '../rule';
|
import { RuleSelector, RuleSources } from '../rule';
|
||||||
import { VERSION_INFO } from '../version';
|
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)
|
// @TODO: this should not need a cast but argv's type only has the last option (include-tag)
|
||||||
// @tslint:disable-next-line:no-any
|
// @tslint:disable-next-line:no-any
|
||||||
const args = parser.argv as 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 {
|
return {
|
||||||
args,
|
args,
|
||||||
mode,
|
mode,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { createLogger } from 'bunyan';
|
import { createLogger } from 'bunyan';
|
||||||
|
import { showCompletionScript } from 'yargs';
|
||||||
|
|
||||||
import { loadConfig } from './config';
|
import { loadConfig } from './config';
|
||||||
import { CONFIG_ARGS_NAME, CONFIG_ARGS_PATH, MODE, parseArgs, VALID_MODES } from './config/args';
|
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> {
|
export async function main(argv: Array<string>): Promise<number> {
|
||||||
const { args, mode } = parseArgs(argv);
|
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 config = await loadConfig(args[CONFIG_ARGS_NAME], ...args[CONFIG_ARGS_PATH]);
|
||||||
|
|
||||||
const logger = createLogger(config.data.logger);
|
const logger = createLogger(config.data.logger);
|
||||||
|
|
Loading…
Reference in New Issue