From 45e8e8492d72b8ab8cd4c6d0e855fac21e8cd0c2 Mon Sep 17 00:00:00 2001 From: Samual Date: Sat, 1 Jun 2024 17:08:46 +0100 Subject: [PATCH] add `formatOption()` which takes an option name and presents it to be prontable with the corrent number of dashes and make it `N` coloured --- src/bin/hsm.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/hsm.ts b/src/bin/hsm.ts index 8834e54..32bae23 100755 --- a/src/bin/hsm.ts +++ b/src/bin/hsm.ts @@ -19,6 +19,7 @@ import { syncMacros } from "../syncMacros" type OptionValue = boolean | number | string +const formatOption = (name: string) => colourN(`-${name.length == 1 ? `` : `-`}${name}`) const options = new Map() const commands: string[] = [] @@ -112,12 +113,11 @@ switch (commands[0]) { const noMinifyOption = popOption(`no-minify`, `skip-minify`) const mangleNamesOption = popOption(`mangle-names`) const forceQuineCheatsOption = popOption(`force-quine-cheats`) - const noMinifyIncompatibleOption = mangleNamesOption || forceQuineCheatsOption if (noMinifyOption && noMinifyIncompatibleOption) { logError( - `Options ${colourN(noMinifyOption.name)} and ${colourN(noMinifyIncompatibleOption.name) + `Options ${formatOption(noMinifyOption.name)} and ${formatOption(noMinifyIncompatibleOption.name) } are incompatible\n` ) @@ -539,7 +539,7 @@ type Option = { name: string, value: OptionValue } function assertOptionIsBoolean(option: Option): asserts option is Replace { if (typeof option.value != `boolean`) { - logError(`The value for ${colourN(option.name)} must be ${colourV(`true`)} or ${colourV(`false`)}\n`) + logError(`The value for ${formatOption(option.name)} must be ${colourV(`true`)} or ${colourV(`false`)}\n`) logHelp() process.exit(1) } @@ -551,7 +551,7 @@ function popOption(...names: string[]): Option | undefined { if (!presentOptionNames.length) return undefined - const presentOptionNamesWithDashDash = presentOptionNames.map(name => colourN(`-${name.length == 1 ? `` : `-`}${name}`)) + const presentOptionNamesWithDashDash = presentOptionNames.map(formatOption) if (presentOptionNames.length > 1) { logError(`The options ${presentOptionNamesWithDashDash.join(`, `) -- knotmirror 0.0.1