Skip to content

Commit 9e76316

Browse files
committed
refine --log-level option help
1 parent 87f16a9 commit 9e76316

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

vti/src/cli.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Command } from 'commander';
2-
import { diagnostics } from './commands/diagnostics';
1+
import { Command, Option } from 'commander';
2+
import { diagnostics, logLevels } from './commands/diagnostics';
33

44
function getVersion(): string {
55
const { version }: { version: string } = require('../package.json');
@@ -13,7 +13,12 @@ function getVersion(): string {
1313
program
1414
.command('diagnostics [workspace]')
1515
.description('Print all diagnostics')
16-
.option('-l, --log-level <logLevel>', 'Log level to print', 'WARN')
16+
.addOption(
17+
new Option('-l, --log-level <logLevel>', 'Log level to print')
18+
.default('WARN')
19+
// logLevels is readonly array but .choices need read-write array (because of weak typing)
20+
.choices((logLevels as unknown) as string[])
21+
)
1722
.action(async (workspace, options) => {
1823
const logLevelOption: unknown = options.logLevel;
1924
if (

vti/src/commands/diagnostics.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import chalk from 'chalk';
2424
import { codeFrameColumns, SourceLocation } from '@babel/code-frame';
2525
import { Range } from 'vscode-languageclient';
2626

27-
export type LogLevel = 'ERROR' | 'WARN' | 'INFO' | 'HINT';
27+
export type LogLevel = typeof logLevels[number];
28+
export const logLevels = ['ERROR', 'WARN', 'INFO', 'HINT'] as const;
2829

2930
export async function diagnostics(workspace: string | null, logLevel: LogLevel) {
3031
console.log('====================================');

0 commit comments

Comments
 (0)