Skip to content

Commit 591fafe

Browse files
Merge pull request #246 from SarahIsWeird/cli-238
Warn if options are passed after commands
2 parents 628a731 + da5883b commit 591fafe

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/bin/hsm.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type OptionValue = boolean | string
2222

2323
const options = new Map<string, OptionValue>
2424
const commands: string[] = []
25+
let didParseOption = false
26+
let didParseOptionAfterCommand = false
2527

2628
for (const argument of process.argv.slice(2)) {
2729
if (argument[0] == `-`) {
@@ -48,8 +50,15 @@ for (const argument of process.argv.slice(2)) {
4850
for (const option of key!.slice(1))
4951
options.set(option, value)
5052
}
51-
} else
53+
54+
didParseOption = true
55+
} else {
56+
if (didParseOption) {
57+
didParseOptionAfterCommand = true
58+
}
59+
5260
commands.push(argument)
61+
}
5362
}
5463

5564
const pushModule = import(`../push`)
@@ -83,6 +92,15 @@ const userColours = new AutoMap<string, string>(user => {
8392

8493
const log = (message: string) => console.log(colourS(message))
8594

95+
if (didParseOptionAfterCommand) {
96+
process.exitCode = 1
97+
98+
console.warn(colourF(`\
99+
${chalk.bold(`Warning:`)} Options should come after commands when calling the script.
100+
This warning will become an error in the next minor version of HSM.`
101+
))
102+
}
103+
86104
if (process.version.startsWith(`v21.`)) {
87105
process.exitCode = 1
88106

0 commit comments

Comments
 (0)