Skip to content

Commit 7f54b48

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 b0ccd83 commit 7f54b48

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ 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+
### Fixed
12+
- Correct CLI argument parsing when using `compile` command to properly identify schema files
13+
914
## 0.17.0 (2025-05-03)
1015

1116
This version of the CLI has a [bug](https://github.com/bare-ts/bare/issues/2) that causes the CLI to fail.

src/bin/bare.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ function main(): void {
8383
} else if (values.version) {
8484
console.info(packageVersion)
8585
} else {
86-
if (positionals.length > 1 && positionals[0] === "compile") {
87-
positionals.pop()
86+
let schemaIndex = 0
87+
88+
if (positionals.length > 0 && positionals[0] === "compile") {
89+
schemaIndex = 1
8890
}
89-
if (positionals.length > 1) {
90-
console.error("only one argument is expected")
91+
if (positionals.length > schemaIndex + 1) {
92+
console.error("only one schema argument is expected")
9193
process.exit(1)
9294
}
93-
const schema = positionals.length > 0 ? positionals[0] : 0
94-
const out = values.out ?? 1
95+
const schema =
96+
positionals.length > schemaIndex ? positionals[schemaIndex] : 0
9597
const generator = values.generator
9698
if (
9799
generator != null &&
@@ -103,13 +105,12 @@ function main(): void {
103105
console.error("Invalid <generator> value")
104106
process.exit(1)
105107
}
106-
compileAction(out, {
108+
compileAction(schema, {
107109
generator,
108110
legacy: values.legacy,
109111
lib: values.lib,
110112
out: values.out,
111113
pedantic: values.pedantic,
112-
schema,
113114
useClass: values["use-class"],
114115
useGenericArray: values["use-generic-array"],
115116
useIntEnum: values["use-int-enum"],

0 commit comments

Comments
 (0)