Skip to content

Commit

Permalink
Update after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Aug 22, 2023
1 parent eee0399 commit 06b633f
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions packages/api/src/parse-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Yargs, { Options, Argv } from "yargs";
import yargs from "yargs";
import yargsToMist from "./yargs-to-mist";
import {
CamelKeys,
Expand All @@ -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 = [];
Expand Down Expand Up @@ -80,19 +78,14 @@ export type CliArgs = ReturnType<typeof parseCli>;
// 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: {
Expand Down Expand Up @@ -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<typeof parsedProm>;

if (parsed.json === true) {
const mistOutput = yargsToMist(allOptions);
const mistOutput = yargsToMist(args);
console.log(JSON.stringify(mistOutput));
process.exit(0);
}
Expand Down

0 comments on commit 06b633f

Please sign in to comment.