From da5883b266481f7e84a2ff7ba73d1f6820749e83 Mon Sep 17 00:00:00 2001 From: SarahIsWeird Date: Mon, 3 Feb 2025 21:50:18 +0100 Subject: [PATCH] issue #238: Warn if options are passed after commands --- src/bin/hsm.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bin/hsm.ts b/src/bin/hsm.ts index 5342a89..8ba025d 100755 --- a/src/bin/hsm.ts +++ b/src/bin/hsm.ts @@ -22,6 +22,8 @@ type OptionValue = boolean | string const options = new Map const commands: string[] = [] +let didParseOption = false +let didParseOptionAfterCommand = false for (const argument of process.argv.slice(2)) { if (argument[0] == `-`) { @@ -48,8 +50,15 @@ for (const argument of process.argv.slice(2)) { for (const option of key!.slice(1)) options.set(option, value) } - } else + + didParseOption = true + } else { + if (didParseOption) { + didParseOptionAfterCommand = true + } + commands.push(argument) + } } const pushModule = import(`../push`) @@ -83,6 +92,15 @@ const userColours = new AutoMap(user => { const log = (message: string) => console.log(colourS(message)) +if (didParseOptionAfterCommand) { + process.exitCode = 1 + + console.warn(colourF(`\ +${chalk.bold(`Warning:`)} Options should come after commands when calling the script. + This warning will become an error in the next minor version of HSM.` + )) +} + if (process.version.startsWith(`v21.`)) { process.exitCode = 1