@@ -4,36 +4,34 @@ import path from 'node:path';
4
4
import process from 'node:process' ;
5
5
import childProcess from 'node:child_process' ;
6
6
import fs from 'node:fs' ;
7
+ import { Command } from 'commander' ;
7
8
import * as utils from '../utils.js' ;
8
9
9
10
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
10
25
11
26
/* eslint-disable no-console */
12
27
async function main ( argv = process . argv ) {
13
- argv = argv . slice ( 2 ) ;
28
+ await program . parseAsync ( argv ) ;
29
+ const options = program . opts ( ) ;
14
30
31
+ const fix = Boolean ( options . fix ) ;
32
+ const useUserConfig = Boolean ( options . userConfig ) ;
33
+ const explicitConfigPath : string | undefined = options . config ;
15
34
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
- }
37
35
38
36
// Resolve which config file to use
39
37
let chosenConfig : string | undefined ;
0 commit comments