Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 158 additions & 40 deletions src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@ export function parseArgs(argv: string[]): { command: CliCommand; options: Parse
if (argv[0] === "advisories" && argv[1] === "sync") {
for (let i = 2; i < argv.length; i++) {
const arg = argv[i];
if (arg === "-h" || arg === "--help") { options.help = true; continue; }
if (arg === "-v" || arg === "--version") { options.version = true; continue; }
if (arg === "--output") { options.output = argv[++i]; continue; }
if (arg.startsWith("--output=")) { options.output = arg.slice("--output=".length); continue; }
if (arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
if (arg === "-h" || arg === "--help") {
options.help = true;
continue;
}
if (arg === "-v" || arg === "--version") {
options.version = true;
continue;
}
if (arg === "--output") {
options.output = argv[++i];
continue;
}
if (arg.startsWith("--output=")) {
options.output = arg.slice("--output=".length);
continue;
}
if (arg.startsWith("-")) {
throw new Error(`Unknown option: ${arg}`);
}
throw new Error(`Unexpected argument: ${arg}`);
}

Expand All @@ -25,8 +39,13 @@ export function parseArgs(argv: string[]): { command: CliCommand; options: Parse
if (argv[0] === "install-skill") {
for (let i = 1; i < argv.length; i++) {
const arg = argv[i];
if (arg === "-h" || arg === "--help") { options.help = true; continue; }
if (arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
if (arg === "-h" || arg === "--help") {
options.help = true;
continue;
}
if (arg.startsWith("-")) {
throw new Error(`Unknown option: ${arg}`);
}
throw new Error(`Unexpected argument: ${arg}`);
}
return { command: "install-skill", options };
Expand All @@ -35,32 +54,111 @@ export function parseArgs(argv: string[]): { command: CliCommand; options: Parse
let projectArg: string | undefined;
for (let i = 0; i < argv.length; i++) {
const arg = argv[i];
if (arg === "-h" || arg === "--help") { options.help = true; continue; }
if (arg === "-v" || arg === "--version") { options.version = true; continue; }
if (arg === "--json") { options.json = true; continue; }
if (arg === "--verbose") { options.verbose = true; continue; }
if (arg === "--fix") { options.fix = true; continue; }
if (arg === "--prod-only") { options.prodOnly = true; continue; }
if (arg === "--offline") { options.offline = true; continue; }
if (arg === "--offline-db") { options.offlineDb = argv[++i]; continue; }
if (arg.startsWith("--offline-db=")) { options.offlineDb = arg.slice("--offline-db=".length); continue; }
if (arg === "--all") { options.all = true; continue; }
if (arg === "--fail-on") { options.failOn = argv[++i] ?? options.failOn; continue; }
if (arg.startsWith("--fail-on=")) { options.failOn = arg.slice("--fail-on=".length); continue; }
if (arg === "--batch-size") { options.batchSize = argv[++i] ?? options.batchSize; continue; }
if (arg.startsWith("--batch-size=")) { options.batchSize = arg.slice("--batch-size=".length); continue; }
if (arg === "--cache-dir") { options.cacheDir = argv[++i]; continue; }
if (arg.startsWith("--cache-dir=")) { options.cacheDir = arg.slice("--cache-dir=".length); continue; }
if (arg === "--osv-url") { options.osvUrl = argv[++i]; continue; }
if (arg.startsWith("--osv-url=")) { options.osvUrl = arg.slice("--osv-url=".length); continue; }
if (arg === "--output") { options.output = argv[++i]; continue; }
if (arg.startsWith("--output=")) { options.output = arg.slice("--output=".length); continue; }
if (arg === "--search-depth") { options.searchDepth = argv[++i] ?? options.searchDepth; continue; }
if (arg.startsWith("--search-depth=")) { options.searchDepth = arg.slice("--search-depth=".length); continue; }
if (arg === "--min-severity") { options.minSeverity = argv[++i] ?? options.minSeverity; continue; }
if (arg.startsWith("--min-severity=")) { options.minSeverity = arg.slice("--min-severity=".length); continue; }
if (arg === "--usage" || arg === "--usage-hints") { options.usage = true; continue; }
if (arg === "--only-used") { options.onlyUsed = true; options.usage = true; continue; }
if (arg === "-h" || arg === "--help") {
options.help = true;
continue;
}
if (arg === "-v" || arg === "--version") {
options.version = true;
continue;
}
if (arg === "--json") {
options.json = true;
continue;
}
if (arg === "--verbose") {
options.verbose = true;
continue;
}
if (arg === "--fix") {
options.fix = true;
continue;
}
if (arg === "--prod-only") {
options.prodOnly = true;
continue;
}
if (arg === "--offline") {
options.offline = true;
continue;
}
if (arg === "--offline-db") {
options.offlineDb = argv[++i];
continue;
}
if (arg.startsWith("--offline-db=")) {
options.offlineDb = arg.slice("--offline-db=".length);
continue;
}
if (arg === "--all") {
options.all = true;
continue;
}
if (arg === "--fail-on") {
options.failOn = argv[++i] ?? options.failOn;
continue;
}
if (arg.startsWith("--fail-on=")) {
options.failOn = arg.slice("--fail-on=".length);
continue;
}
if (arg === "--batch-size") {
options.batchSize = argv[++i] ?? options.batchSize;
continue;
}
if (arg.startsWith("--batch-size=")) {
options.batchSize = arg.slice("--batch-size=".length);
continue;
}
if (arg === "--cache-dir") {
options.cacheDir = argv[++i];
continue;
}
if (arg.startsWith("--cache-dir=")) {
options.cacheDir = arg.slice("--cache-dir=".length);
continue;
}
if (arg === "--osv-url") {
options.osvUrl = argv[++i];
continue;
}
if (arg.startsWith("--osv-url=")) {
options.osvUrl = arg.slice("--osv-url=".length);
continue;
}
if (arg === "--output") {
options.output = argv[++i];
continue;
}
if (arg.startsWith("--output=")) {
options.output = arg.slice("--output=".length);
continue;
}
if (arg === "--search-depth") {
options.searchDepth = argv[++i] ?? options.searchDepth;
continue;
}
if (arg.startsWith("--search-depth=")) {
options.searchDepth = arg.slice("--search-depth=".length);
continue;
}
if (arg === "--min-severity") {
options.minSeverity = argv[++i] ?? options.minSeverity;
continue;
}
if (arg.startsWith("--min-severity=")) {
options.minSeverity = arg.slice("--min-severity=".length);
continue;
}
if (arg === "--usage" || arg === "--usage-hints") {
options.usage = true;
continue;
}
if (arg === "--only-used") {
options.onlyUsed = true;
options.usage = true;
continue;
}
if (arg === "--report") {
const next = argv[i + 1];
if (next !== undefined && !next.startsWith("-")) {
Expand All @@ -71,13 +169,33 @@ export function parseArgs(argv: string[]): { command: CliCommand; options: Parse
}
continue;
}
if (arg.startsWith("--report=")) { options.report = arg.slice("--report=".length); continue; }
if (arg === "--no-open") { options.noOpen = true; continue; }
if (arg === "--no-cache") { options.noCache = true; continue; }
if (arg === "--sarif") { options.sarif = true; continue; }
if (arg === "--cdx") { options.cdx = true; continue; }
if (arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
if (!projectArg) { projectArg = arg; continue; }
if (arg.startsWith("--report=")) {
options.report = arg.slice("--report=".length);
continue;
}
if (arg === "--no-open") {
options.noOpen = true;
continue;
}
if (arg === "--no-cache") {
options.noCache = true;
continue;
}
if (arg === "--sarif") {
options.sarif = true;
continue;
}
if (arg === "--cdx") {
options.cdx = true;
continue;
}
if (arg.startsWith("-")) {
throw new Error(`Unknown option: ${arg}`);
}
if (!projectArg) {
projectArg = arg;
continue;
}
throw new Error(`Unexpected argument: ${arg}`);
}

Expand Down