fix: Extend OptionDefinition from command-line-args, fix positional arg bug (#2767)

* add command-line-args as devDep to core

* extend option definition type from command line args

* add map from optionType to type
This commit is contained in:
inferrinizzard
2025-05-26 09:54:12 -07:00
committed by GitHub
parent b747e4b01a
commit 4195020560
4 changed files with 15 additions and 5 deletions

1
package-lock.json generated
View File

@ -5930,6 +5930,7 @@
"@types/unicode-properties": "^1.3.0",
"@types/urijs": "^1.19.25",
"@types/wordwrap": "^1.0.3",
"command-line-args": "^5.2.1",
"typescript": "~5.8.3"
}
},

View File

@ -36,6 +36,7 @@
"@types/unicode-properties": "^1.3.0",
"@types/urijs": "^1.19.25",
"@types/wordwrap": "^1.0.3",
"command-line-args": "^5.2.1",
"typescript": "~5.8.3"
},
"overrides": {

View File

@ -1,4 +1,5 @@
import type { EnumOption, Option } from "./index";
import type { OptionDefinition as CommandLineArgsOptionDefinition } from "command-line-args";
/**
* Primary options show up in the web UI in the "Language" settings tab,
@ -6,16 +7,16 @@ import type { EnumOption, Option } from "./index";
* CLI is only for cli
*/
export type OptionKind = "primary" | "secondary" | "cli";
export type OptionType = "string" | "boolean" | "enum";
export interface OptionDefinition<Name extends string = string, T = unknown> {
export interface OptionDefinition<Name extends string = string, T = unknown>
extends CommandLineArgsOptionDefinition {
/** Option Name */
name: Name;
/** Option Alias for CLI */
alias?: string;
/** Option Description */
description: string;
/** Category of Option */
optionType: "string" | "boolean" | "enum";
optionType: OptionType;
/** Default Value for Option */
defaultValue?: T;
/** Enum only, map of possible keys and values */

View File

@ -455,6 +455,7 @@ function makeOptionDefinitions(
typeLabel: "FILE|URL|DIRECTORY",
description: "The file, url, or data directory to type.",
kind: "cli",
defaultOption: true,
},
{
name: "src-urls",
@ -725,7 +726,13 @@ function parseOptions(
): Partial<CLIOptions> {
let opts: commandLineArgs.CommandLineOptions;
try {
opts = commandLineArgs(definitions, { argv, partial });
opts = commandLineArgs(
definitions.map((def) => ({
...def,
type: def.optionType === "boolean" ? Boolean : String,
})),
{ argv, partial },
);
} catch (e) {
assert(!partial, "Partial option parsing should not have failed");
return messageError("DriverCLIOptionParsingFailed", {