Skip to content

Commit d703fb8

Browse files
committed
feat: added commnder to lint.ts and reimplemented cli options using it
1 parent b89683a commit d703fb8

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/bin/lint.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,34 @@ import path from 'node:path';
44
import process from 'node:process';
55
import childProcess from 'node:child_process';
66
import fs from 'node:fs';
7+
import { Command } from 'commander';
78
import * as utils from '../utils.js';
89

910
const platform = os.platform();
11+
const program = new Command();
12+
13+
program
14+
.name('matrixai-lint')
15+
.description(
16+
'Lint source files, scripts, and markdown with configured rules.',
17+
)
18+
.option('-f, --fix', 'Automatically fix problems')
19+
.option(
20+
'--user-config',
21+
'Use user-provided ESLint config instead of built-in one',
22+
)
23+
.option('--config <path>', 'Path to explicit ESLint config file')
24+
.allowUnknownOption(false); // Optional: force rejection of unknown flags
1025

1126
/* eslint-disable no-console */
1227
async function main(argv = process.argv) {
13-
argv = argv.slice(2);
28+
await program.parseAsync(argv);
29+
const options = program.opts();
1430

31+
const fix = Boolean(options.fix);
32+
const useUserConfig = Boolean(options.userConfig);
33+
const explicitConfigPath: string | undefined = options.config;
1534
let hadFailure = false;
16-
let fix = false;
17-
let useUserConfig = false;
18-
let explicitConfigPath: string | undefined;
19-
const restArgs: string[] = [];
20-
21-
while (argv.length > 0) {
22-
const option = argv.shift()!;
23-
switch (option) {
24-
case '--fix':
25-
fix = true;
26-
break;
27-
case '--user-config':
28-
useUserConfig = true;
29-
break;
30-
case '--config':
31-
explicitConfigPath = argv.shift(); // Grab the next token
32-
break;
33-
default:
34-
restArgs.push(option);
35-
}
36-
}
3735

3836
// Resolve which config file to use
3937
let chosenConfig: string | undefined;

0 commit comments

Comments
 (0)