diff --git a/lib/cli/cli-options.ts b/lib/cli/cli-options.ts index ad0b515ba..ca7fba431 100644 --- a/lib/cli/cli-options.ts +++ b/lib/cli/cli-options.ts @@ -53,6 +53,7 @@ export function merge(input) { appendServerDirectoryOption, handleProxyOption, handlePortsOption, + handleHostOption, handleGhostModeOption, handleFilesOption, handleExtensionsOption, diff --git a/lib/cli/transforms/handleHostOption.ts b/lib/cli/transforms/handleHostOption.ts new file mode 100644 index 000000000..7ec79b711 --- /dev/null +++ b/lib/cli/transforms/handleHostOption.ts @@ -0,0 +1,35 @@ +import {BsTempOptions, TransformResult} from "../cli-options"; +import {BsErrorLevels, BsErrorTypes} from "../../bin"; + +export function handleHostOption(incoming: BsTempOptions): TransformResult { + const host: string|null = incoming.get("host"); + const listen: string|null = incoming.get("listen"); + + if (host && listen) { + if (host !== listen) { + return [incoming, [{ + errors: [ + { + error: new Error("Cannot specify both `host` and `listen` options"), + meta() { + return [ + "", + "Tip: Use just the `listen` option *only* if you want to bind only to a particular host.", + ] + } + } + ], + level: BsErrorLevels.Fatal, + type: BsErrorTypes.HostAndListenIncompatible + }]]; + } + + // whenever we have have both `host` + `listen` options, + // we remove the 'host' to prevent complication further down the line + return [ + incoming.delete('host'), + []]; + } + + return [incoming, []]; +}