-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.ts
60 lines (47 loc) · 1.15 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
import { reproduce, ReproduceResult } from './index.js';
// @ts-ignore
import { minargs } from 'minargs';
const usage = `USAGE:
$ reproduce <package> [<options>]
OPTIONS: DESCRIPTION:
-s, --strategy Choose a strategy (default: "npm")
-j, --json Output result as JSON
-h, --help Print usage information
`;
const opts = {
alias: {
s: 'strategy',
j: 'json',
h: 'help'
}
};
const { positionals, args } = minargs(opts);
// Check if the help flag was passed
if (args.help) {
printUsage();
process.exit(0);
}
// Check if a positional argument was passed
if (positionals.length === 0) {
printUsage();
process.exit(1);
}
// Run the reproduce function
async function main() {
const result = await reproduce(positionals[0], {
strategy: args?.strategy?.[0] || 'npm'
});
if (result && args.json) {
console.log(JSON.stringify(result, null, 2));
}
process.exit(result ? (result as ReproduceResult).reproduced ? 0 : 1 : 2);
}
main().catch(err => {
console.error('Error:', err);
process.exit(2);
});
// Print usage information
function printUsage(): void {
console.log(usage);
}