diff --git a/vti/src/cli.ts b/vti/src/cli.ts index 4a28a566cc..0596393039 100644 --- a/vti/src/cli.ts +++ b/vti/src/cli.ts @@ -1,11 +1,15 @@ import { Command, Option } from 'commander'; -import { diagnostics, logLevels } from './commands/diagnostics'; +import { diagnostics, LogLevel, logLevels } from './commands/diagnostics'; function getVersion(): string { const { version }: { version: string } = require('../package.json'); return `v${version}`; } +function validateLogLevel(logLevelInput: unknown): logLevelInput is LogLevel { + return typeof logLevelInput === 'string' && (logLevels as ReadonlyArray).includes(logLevelInput); +} + (async () => { const program = new Command(); program.name('vti').description('Vetur Terminal Interface').version(getVersion()); @@ -21,12 +25,7 @@ function getVersion(): string { ) .action(async (workspace, options) => { const logLevelOption: unknown = options.logLevel; - if ( - logLevelOption !== 'ERROR' && - logLevelOption !== 'WARN' && - logLevelOption !== 'INFO' && - logLevelOption !== 'HINT' - ) { + if (!validateLogLevel(logLevelOption)) { throw new Error(`Invalid log level: ${logLevelOption}`); } await diagnostics(workspace, logLevelOption);