From 5eebfeed29de7aa48d9495e3e808c4b53d16bdf3 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Fri, 3 Dec 2021 10:44:56 -0500 Subject: [PATCH] fix: parse cli `time` option correctly --- .../ethereum/options/src/chain-options.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/chains/ethereum/options/src/chain-options.ts b/src/chains/ethereum/options/src/chain-options.ts index fcc4df15b2..d6d3b23e2d 100644 --- a/src/chains/ethereum/options/src/chain-options.ts +++ b/src/chains/ethereum/options/src/chain-options.ts @@ -97,13 +97,14 @@ export type ChainConfig = { */ readonly time: { type: Date; - rawType: Date | string; + rawType: Date | string | number; legacy: { /** * @deprecated Use chain.time instead */ time: Date | string; }; + cliType: string; }; /** @@ -175,17 +176,21 @@ export const ChainOptions: Definitions = { cliType: "number" }, time: { - normalize: rawInput => { - if (typeof rawInput === "string") { - return new Date(rawInput); - } else { - return rawInput; - } - }, + normalize: rawInput => new Date(rawInput), cliDescription: "Date that the first block should start.", legacyName: "time", cliAliases: ["t", "time"], - cliType: "number" + cliType: "string", + cliCoerce: (input: string) => { + // try parsing the input as a number, if it works use the number + // otherwise pass the string along + const asNum = (input as any) / 1; + if (isNaN(asNum)) { + return input; + } else { + return asNum; + } + } }, hardfork: { normalize,