Skip to content

Commit f7eaba2

Browse files
committed
feat: replace yargs with cac for CLI command handling
1 parent 94a77b1 commit f7eaba2

File tree

4 files changed

+31
-136
lines changed

4 files changed

+31
-136
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@typescript-eslint/eslint-plugin": "catalog:prod",
9292
"@typescript-eslint/parser": "catalog:prod",
9393
"@vitest/eslint-plugin": "catalog:prod",
94+
"cac": "catalog:prod",
9495
"eslint-config-flat-gitignore": "catalog:prod",
9596
"eslint-config-prettier": "catalog:prod",
9697
"eslint-plugin-antfu": "catalog:prod",
@@ -114,16 +115,14 @@
114115
"parse-gitignore": "catalog:prod",
115116
"prompts": "catalog:prod",
116117
"vue-eslint-parser": "catalog:prod",
117-
"yaml-eslint-parser": "catalog:prod",
118-
"yargs": "catalog:prod"
118+
"yaml-eslint-parser": "catalog:prod"
119119
},
120120
"devDependencies": {
121121
"@eslint-react/eslint-plugin": "catalog:peer",
122122
"@eslint/config-inspector": "catalog:dev",
123123
"@types/eslint-config-prettier": "catalog:dev",
124124
"@types/node": "catalog:dev",
125125
"@types/prompts": "catalog:dev",
126-
"@types/yargs": "catalog:dev",
127126
"@unocss/eslint-plugin": "catalog:peer",
128127
"bumpp": "catalog:dev",
129128
"eslint": "catalog:peer",

pnpm-lock.yaml

Lines changed: 6 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
catalogs:
22
dev:
3-
'@antfu/ni': ^27.0.1
43
'@eslint/config-inspector': ^1.3.0
54
'@types/eslint-config-prettier': ^6.11.3
65
'@types/node': ^24.9.2
76
'@types/prompts': ^2.4.9
8-
'@types/yargs': ^17.0.34
97
bumpp: ^10.3.1
108
eslint-typegen: ^2.3.0
119
jiti: ^2.6.1
@@ -33,6 +31,7 @@ catalogs:
3331
'@typescript-eslint/eslint-plugin': ^8.46.2
3432
'@typescript-eslint/parser': ^8.46.2
3533
'@vitest/eslint-plugin': ^1.3.26
34+
cac: ^6.7.14
3635
eslint-config-flat-gitignore: ^2.1.0
3736
eslint-config-prettier: ^10.1.8
3837
eslint-plugin-antfu: ^3.1.1
@@ -57,7 +56,6 @@ catalogs:
5756
prompts: ^2.4.2
5857
vue-eslint-parser: ^10.2.0
5958
yaml-eslint-parser: ^1.3.0
60-
yargs: ^18.0.0
6159
onlyBuiltDependencies:
6260
- esbuild
6361
- simple-git-hooks

src/cli/index.ts

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import process from 'node:process'
22
import { styleText } from 'node:util'
3-
import yargs from 'yargs'
4-
import { hideBin } from 'yargs/helpers'
3+
import { cac } from 'cac'
54
import { CROSS, version } from './constants'
65
import { run } from './run'
76

@@ -11,36 +10,25 @@ function header() {
1110
)
1211
}
1312

14-
const instance = yargs(hideBin(process.argv))
15-
.scriptName('@coderwyd/eslint-config')
16-
.usage('')
17-
.command(
18-
'*',
19-
'Run the initialization or migration',
20-
(args) =>
21-
args
22-
.option('yes', {
23-
alias: 'y',
24-
description: 'Skip prompts and use default values',
25-
type: 'boolean',
26-
})
27-
.help(),
28-
async (args) => {
29-
header()
30-
console.log()
31-
try {
32-
await run(args)
33-
} catch (error) {
34-
console.error(styleText(['red', 'inverse'], ' Failed to migrate '))
35-
console.error(styleText('red', `${CROSS} ${String(error)}`))
36-
process.exit(1)
37-
}
38-
},
39-
)
40-
.showHelpOnFail(false)
41-
.alias('h', 'help')
42-
.version('version', version)
43-
.alias('v', 'version')
13+
const cli = cac('@coderwyd/eslint-config')
14+
15+
cli
16+
.command('', 'Run the initialization or migration')
17+
.option('--yes, -y', 'Skip prompts and use default values', {
18+
default: false,
19+
})
20+
.action(async (args) => {
21+
header()
22+
console.log()
23+
try {
24+
await run(args)
25+
} catch (error) {
26+
console.error(styleText(['red', 'inverse'], ' Failed to migrate '))
27+
console.error(styleText('red', `${CROSS} ${String(error)}`))
28+
process.exit(1)
29+
}
30+
})
4431

45-
// eslint-disable-next-line ts/no-unused-expressions
46-
instance.help().argv
32+
cli.help()
33+
cli.version(version)
34+
cli.parse()

0 commit comments

Comments
 (0)