forked from FluffyLabs/jam-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs.ts
More file actions
95 lines (85 loc) · 2.77 KB
/
Copy pathargs.ts
File metadata and controls
95 lines (85 loc) · 2.77 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import minimist from "minimist";
export type Args = {
directory: string;
socket: string;
repeat: number;
flavour: "tiny" | "full";
mode: "default" | "jam-traces";
output?: string;
capture?: string;
ignore: string[];
};
export function parseArgs(): Args {
const argv = minimist(process.argv.slice(2), {
alias: {
s: "stats",
f: "flavour",
r: "repeat",
m: "mode",
c: "capture",
h: "help",
},
default: {
repeat: 1,
mode: "default",
},
string: ["directory", "socket", "mode", "ignore", "capture"],
});
if (argv.help) {
console.log("Usage: picofuzz [options] <directory> <socket>");
console.log("");
console.log("Options:");
console.log(" -f, --flavour <spec> JAM spec: tiny | full (default: tiny)");
console.log(" -m, --mode <mode> Processing mode: default | jam-traces (default: default)");
console.log(" -r, --repeat <count> Number of repetitions (default: 1)");
console.log(" -s, --stats <file> Append aggregated stats to a CSV file");
console.log(" -c, --capture <dir> Capture request/response pairs as minifuzz trace files");
console.log(" --ignore <file> Ignore specific .bin files (can be repeated)");
console.log(" -h, --help Show help");
console.log("");
console.log("Positional arguments:");
console.log(" picofuzz <directory> <socket> [repeat]");
process.exit(0);
}
// Support both flag-based and positional arguments
const directory = argv._[0];
const socket = argv._[1];
const repeat = argv.repeat;
const flavour = argv.flavour ?? "tiny";
const mode = argv.mode ?? "default";
const output = argv.stats;
const capture = argv.capture;
if (!directory || !socket) {
console.error("Error: directory and socket are required");
console.error("Usage: picofuzz [options] <directory> <socket>");
console.error("Use --help for more information");
process.exit(1);
}
if (Number.isNaN(repeat) || repeat < 1) {
console.error(`Invalid repeat value: ${repeat}`);
console.error("Repeat must be a positive number");
process.exit(1);
}
if (flavour !== "tiny" && flavour !== "full") {
console.error(`Invalid flavour value: ${flavour}`);
console.error("Must be either 'tiny' or 'full'");
process.exit(1);
}
if (mode !== "default" && mode !== "jam-traces") {
console.error(`Invalid mode value: ${mode}`);
console.error("Must be either 'default' or 'jam-traces'");
process.exit(1);
}
const ignoreRaw = argv.ignore;
const ignore: string[] = ignoreRaw === undefined ? [] : Array.isArray(ignoreRaw) ? ignoreRaw : [ignoreRaw];
return {
directory,
socket,
repeat,
flavour,
mode,
output,
capture,
ignore,
};
}