diff --git a/packages/api/src/parse-cli.ts b/packages/api/src/parse-cli.ts index 5e2a742a31..ed415ea433 100755 --- a/packages/api/src/parse-cli.ts +++ b/packages/api/src/parse-cli.ts @@ -1,4 +1,4 @@ -import Yargs, { Options, Argv } from "yargs"; +import yargs from "yargs"; import yargsToMist from "./yargs-to-mist"; import { CamelKeys, @@ -14,8 +14,6 @@ const DEFAULT_ARWEAVE_GATEWAY_PREFIXES = [ "https://gateway.arweave.net/", ]; -const yargs = Yargs() as unknown as Argv; - function coerceArr(arg: any) { if (!Array.isArray(arg)) { const arr = []; @@ -80,19 +78,14 @@ export type CliArgs = ReturnType; // before passing it to yargs completely breaks type inference, which is a huge shame. // So... this monkeypatches yargs to capture that variable. If you know of a more // elegant way, I'd love to hear it! -let allOptions: { [key: string]: Options }; +let args; const originalOpts = yargs.options; -yargs.options = function (...args) { - if (!allOptions) { - allOptions = args[0]; - } - return originalOpts.call(this, ...args); +yargs.options = function (arg) { + args = arg; + return originalOpts.call(this, arg); }; export default function parseCli(argv?: string | readonly string[]) { - if (!argv) { - argv = process.argv.slice(2); - } const parsedProm = yargs .options({ port: { @@ -466,8 +459,9 @@ export default function parseCli(argv?: string | readonly string[]) { .parse(argv); // yargs returns a Promise even tho we don't have any async middlewares const parsed = parsedProm as Awaited; + if (parsed.json === true) { - const mistOutput = yargsToMist(allOptions); + const mistOutput = yargsToMist(args); console.log(JSON.stringify(mistOutput)); process.exit(0); }