1
0
Fork 0

fix: print completion or rules before attempting to load source

This commit is contained in:
ssube 2019-07-04 10:35:27 -05:00
parent afafdddcf0
commit 8b9d84ef87
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 18 additions and 7 deletions

View File

@ -91,6 +91,7 @@ const bundle = {
'Type',
],
'node_modules/yargs/index.js': [
'showCompletionScript',
'usage',
],
},

View File

@ -1,5 +1,5 @@
import { createLogger } from 'bunyan';
import { Options, usage } from 'yargs';
import { Options, showCompletionScript, usage } from 'yargs';
import { loadConfig } from 'src/config';
import { YamlParser } from 'src/parser/YamlParser';
@ -53,6 +53,13 @@ export async function main(argv: Array<string>): Promise<number> {
mode = 'list';
},
})
.command({
command: ['complete'],
describe: 'generate tab completion script for bash or zsh',
handler: (argv) => {
mode = 'complete';
},
})
.option(CONFIG_ARGS_NAME, {
default: `.${VERSION_INFO.app.name}.yml`,
group: 'Config:',
@ -99,14 +106,17 @@ export async function main(argv: Array<string>): Promise<number> {
...RULE_OPTION,
alias: ['t', 'tag'],
})
.completion('completion', 'generate command completion for bash or zsh')
.help()
.version(VERSION_INFO.app.version)
.alias('version', 'v')
.argv;
const config = await loadConfig(args[CONFIG_ARGS_NAME], ...args[CONFIG_ARGS_PATH]);
if (mode === 'complete') {
showCompletionScript();
return STATUS_SUCCESS;
}
const config = await loadConfig(args[CONFIG_ARGS_NAME], ...args[CONFIG_ARGS_PATH]);
const logger = createLogger(config.data.logger);
logger.info(VERSION_INFO, 'version info');
logger.info({ args }, 'main arguments');
@ -131,10 +141,6 @@ export async function main(argv: Array<string>): Promise<number> {
logger,
});
const parser = new YamlParser();
const source = await loadSource(args.source);
let docs = parser.parse(source);
const rules = await loadRules(args.rules, ctx.ajv);
const activeRules = await resolveRules(rules, args as any);
@ -143,6 +149,10 @@ export async function main(argv: Array<string>): Promise<number> {
return STATUS_SUCCESS;
}
const parser = new YamlParser();
const source = await loadSource(args.source);
let docs = parser.parse(source);
for (const data of docs) {
await visitRules(ctx, activeRules, data);
}