From 8efbd992dfc07d7af7e5f42cf1e499bd55ace05a Mon Sep 17 00:00:00 2001 From: ssube Date: Mon, 24 Jun 2019 23:47:12 -0500 Subject: [PATCH] feat: list mode, fix version option --- config/rollup.js | 1 + src/index.ts | 12 +++++++++--- src/version.ts | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/rollup.js b/config/rollup.js index b560d4a..0f3be1e 100644 --- a/config/rollup.js +++ b/config/rollup.js @@ -23,6 +23,7 @@ export default { delimiters: ['{{ ', ' }}'], values: { APP_NAME: metadata.name, + APP_VERSION: metadata.version, BUILD_JOB: process.env['CI_JOB_ID'], BUILD_RUNNER: process.env['CI_ENVIRONMENT_SLUG'], GIT_BRANCH: process.env['CI_COMMIT_REF_SLUG'], diff --git a/src/index.ts b/src/index.ts index 06e3893..f34c98e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ import { VisitorContext } from 'src/visitor/context'; const CONFIG_ARGS_NAME = 'config-name'; const CONFIG_ARGS_PATH = 'config-path'; -const MODES = ['check', 'fix']; +const MODES = ['check', 'fix', 'list']; const RULE_OPTION: Options = { default: [], @@ -54,7 +54,7 @@ const MAIN_ARGS = usage(`Usage: salty-dog [options]`) }) .option('mode', { alias: ['m'], - choices: ['check', 'fix'], + choices: MODES, default: 'check', type: 'string', }) @@ -78,7 +78,8 @@ const MAIN_ARGS = usage(`Usage: salty-dog [options]`) ...RULE_OPTION, alias: ['t', 'tag'], }) - .help(); + .help() + .version(VERSION_INFO.app.version); const STATUS_SUCCESS = 0; const STATUS_ERROR = 1; @@ -116,6 +117,11 @@ export async function main(argv: Array): Promise { const rules = await loadRules(args.rules, ctx.ajv); const activeRules = await resolveRules(rules, args as any); + if (args.mode === 'list') { + logger.info({rules: activeRules}, 'listing active rules'); + return STATUS_SUCCESS; + } + for (const data of docs) { for (const rule of activeRules) { const items = await rule.pick(ctx, data); diff --git a/src/version.ts b/src/version.ts index 2edf312..6c949a3 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,6 +1,7 @@ export const VERSION_INFO = { app: { name: '{{ APP_NAME }}', + version: '{{ APP_VERSION }}', }, build: { job: '{{ BUILD_JOB }}',