Skip to content

Commit

Permalink
complain about unrecognised options #162
Browse files Browse the repository at this point in the history
  • Loading branch information
samualtnorman committed Jun 1, 2024
1 parent 45e8e84 commit 6a2a079
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/bin/hsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ switch (commands[0]) {
process.exit(1)
}

complainAboutUnrecognisedOptions()

const { processScript } = await processScriptModule
const fileBaseName = getPathBaseName(target, fileExtension)
const fileBaseNameEndsWithDotSrc = fileBaseName.endsWith(`.src`)
Expand Down Expand Up @@ -236,6 +238,8 @@ switch (commands[0]) {
if (commands[0] == `push`) {
const { push, MissingSourceFolderError, MissingHackmudFolderError, NoUsersError } = await pushModule

complainAboutUnrecognisedOptions()

const infos = await push(sourcePath, hackmudPath, {
scripts,
onPush: info => logInfo(info, hackmudPath),
Expand Down Expand Up @@ -263,6 +267,8 @@ ${colourN(`--hackmud-path`)}=${colourB(`<path>`)} option or ${colourN(`HSM_HACKM
const typeDeclarationPathOption =
popOption(`type-declaration-path`, `type-declaration`, `dts`, `gen-types`)

complainAboutUnrecognisedOptions()

const { watch } = await watchModule

watch(sourcePath, hackmudPath, {
Expand Down Expand Up @@ -290,6 +296,8 @@ ${colourN(`--hackmud-path`)}=${colourB(`<path>`)} option or ${colourN(`HSM_HACKM
process.exit(1)
}

complainAboutUnrecognisedOptions()

const sourcePath = commands[2] || `.`

await pull(sourcePath, hackmudPath, script).catch(error => {
Expand All @@ -300,6 +308,9 @@ ${colourN(`--hackmud-path`)}=${colourB(`<path>`)} option or ${colourN(`HSM_HACKM

case `sync-macros`: {
const hackmudPath = getHackmudPath()

complainAboutUnrecognisedOptions()

const { macrosSynced, usersSynced } = await syncMacros(hackmudPath)

log(`Synced ${macrosSynced} macros to ${usersSynced} users`)
Expand All @@ -318,6 +329,8 @@ ${colourN(`--hackmud-path`)}=${colourB(`<path>`)} option or ${colourN(`HSM_HACKM
process.exit(1)
}

complainAboutUnrecognisedOptions()

const sourcePath = resolvePath(target)
const outputPath = commands[2] || `./player.d.ts`

Expand Down Expand Up @@ -566,3 +579,13 @@ function popOption(...names: string[]): Option | undefined {

return { name: presentOptionNamesWithDashDash[0]!, value }
}

function complainAboutUnrecognisedOptions(): void {
if (options.size) {
logError(
`Unrecognised option${options.size > 1 ? `s` : ``}: ${[ ...options.keys() ].map(formatOption).join(`, `)}`
)

process.exit(1)
}
}

0 comments on commit 6a2a079

Please sign in to comment.