Skip to content

Commit d8cd023

Browse files
authored
feat: replace Yargs with Commander (#736)
Signed-off-by: Alfi Maulana <[email protected]>
1 parent 655509e commit d8cd023

File tree

3 files changed

+19
-91
lines changed

3 files changed

+19
-91
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626
"test": "vitest run"
2727
},
2828
"dependencies": {
29-
"yargs": "^17.7.2"
29+
"commander": "^13.1.0"
3030
},
3131
"devDependencies": {
3232
"@eslint/js": "^9.22.0",
3333
"@tsconfig/node23": "^23.0.0",
3434
"@types/node": "^22.13.11",
35-
"@types/yargs": "^17.0.33",
3635
"@vitest/coverage-v8": "^3.0.5",
3736
"eslint": "^9.22.0",
3837
"lefthook": "^1.11.3",

pnpm-lock.yaml

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

src/bin.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
#!/usr/bin/env node
22

3-
import yargs from "yargs";
4-
import { hideBin } from "yargs/helpers";
3+
import { program } from "commander";
54
import { fibonacciSequence } from "./sequence.js";
65

7-
yargs(hideBin(process.argv))
8-
.scriptName("my_fibonacci")
6+
program
7+
.name("my_fibonacci")
98
.version("0.0.0")
10-
.command(
11-
"$0 <n>",
12-
"Generate a Fibonacci sequence up to the given number of terms.",
13-
(yargs) =>
14-
yargs.positional("n", {
15-
demandOption: true,
16-
describe: "The number of terms",
17-
type: "number",
18-
}),
19-
(argv) => {
20-
process.stdout.write(fibonacciSequence(argv.n).join(" ") + "\n");
21-
},
22-
)
9+
.description("Generate a Fibonacci sequence up to the given number of terms.")
10+
.argument("<n>", "The number of terms", parseInt)
11+
.action((n) => {
12+
const sequence = fibonacciSequence(n);
13+
process.stdout.write(`${sequence.join(" ")}\n`);
14+
})
2315
.parse();

0 commit comments

Comments
 (0)