Skip to content

Commit d7056a5

Browse files
merlindiavovaMerlin Diavova
authored andcommitted
fix(cli): correct positional argument parsing (#3)
- Fix handling of 'compile' command in positional arguments - Ensure schema file is properly identified when using compile command - Prevent incorrect assignment of output file as schema input - Maintain backward compatibility with existing command usage Co-authored-by: Merlin Diavova <merlin@amespalsh.co.uk>
1 parent 63e47c4 commit d7056a5

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning][semver].
66
The format of this changelog is [a variant][lib9-versionning] of [Keep a Changelog][keep-changelog].
77
New entries must be placed in a section entitled `Unreleased`.
88

9+
## Unreleased
10+
11+
- Fix CLI argument parsing when using `compile` command to properly identify schema files
12+
913
## 0.16.0 (2024-11-02)
1014

1115
- BREAKING CHANGES: require Node.js 20.0.0 or above

src/bin/cli.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ function main(): void {
8484
} else if (values.version) {
8585
console.info(VERSION)
8686
} else {
87-
if (positionals.length > 1 && positionals[0] === "compile") {
88-
positionals.pop()
87+
let schemaIndex = 0
88+
if (positionals.length > 0 && positionals[0] === "compile") {
89+
schemaIndex = 1
8990
}
90-
if (positionals.length > 1) {
91-
console.error("only one argument is expected")
91+
if (positionals.length > schemaIndex + 1) {
92+
console.error("only one schema argument is expected")
9293
process.exit(1)
9394
}
94-
const schema = positionals.length > 0 ? positionals[0] : 0
95-
const out = values.out ?? 1
95+
const schema =
96+
positionals.length > schemaIndex ? positionals[schemaIndex] : 0
9697
const generator = values.generator
9798
if (
9899
generator != null &&
@@ -104,13 +105,12 @@ function main(): void {
104105
console.error("Invalid <generator> value")
105106
process.exit(1)
106107
}
107-
compileAction(out, {
108+
compileAction(schema, {
108109
generator,
109110
legacy: values.legacy,
110111
lib: values.lib,
111112
out: values.out,
112113
pedantic: values.pedantic,
113-
schema,
114114
useClass: values["use-class"],
115115
useGenericArray: values["use-generic-array"],
116116
useIntEnum: values["use-int-enum"],

0 commit comments

Comments
 (0)