Skip to content

Commit 4195020

Browse files
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
1 parent b747e4b commit 4195020

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/quicktype-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@types/unicode-properties": "^1.3.0",
3737
"@types/urijs": "^1.19.25",
3838
"@types/wordwrap": "^1.0.3",
39+
"command-line-args": "^5.2.1",
3940
"typescript": "~5.8.3"
4041
},
4142
"overrides": {

packages/quicktype-core/src/RendererOptions/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import type { EnumOption, Option } from "./index";
2+
import type { OptionDefinition as CommandLineArgsOptionDefinition } from "command-line-args";
23

34
/**
45
* Primary options show up in the web UI in the "Language" settings tab,
56
* Secondary options in "Other".
67
* CLI is only for cli
78
*/
89
export type OptionKind = "primary" | "secondary" | "cli";
10+
export type OptionType = "string" | "boolean" | "enum";
911

10-
export interface OptionDefinition<Name extends string = string, T = unknown> {
12+
export interface OptionDefinition<Name extends string = string, T = unknown>
13+
extends CommandLineArgsOptionDefinition {
1114
/** Option Name */
1215
name: Name;
13-
/** Option Alias for CLI */
14-
alias?: string;
1516
/** Option Description */
1617
description: string;
1718
/** Category of Option */
18-
optionType: "string" | "boolean" | "enum";
19+
optionType: OptionType;
1920
/** Default Value for Option */
2021
defaultValue?: T;
2122
/** Enum only, map of possible keys and values */

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ function makeOptionDefinitions(
455455
typeLabel: "FILE|URL|DIRECTORY",
456456
description: "The file, url, or data directory to type.",
457457
kind: "cli",
458+
defaultOption: true,
458459
},
459460
{
460461
name: "src-urls",
@@ -725,7 +726,13 @@ function parseOptions(
725726
): Partial<CLIOptions> {
726727
let opts: commandLineArgs.CommandLineOptions;
727728
try {
728-
opts = commandLineArgs(definitions, { argv, partial });
729+
opts = commandLineArgs(
730+
definitions.map((def) => ({
731+
...def,
732+
type: def.optionType === "boolean" ? Boolean : String,
733+
})),
734+
{ argv, partial },
735+
);
729736
} catch (e) {
730737
assert(!partial, "Partial option parsing should not have failed");
731738
return messageError("DriverCLIOptionParsingFailed", {

0 commit comments

Comments
 (0)