From 5b79861c6dadc04545f6a922cf89987a2d06b7ee Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 14 Feb 2024 15:35:31 -0500 Subject: [PATCH] Simplify help function --- src/commands/deploy.ts | 10 +++++----- src/commands/get-approval-process.ts | 10 +++++----- src/commands/propose-upgrade.ts | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index 0080688..d7374ff 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -26,7 +26,7 @@ Additional options: export async function deploy(args: string[], deployClient?: DeployClient): Promise { const { parsedArgs, extraArgs } = parseArgs(args); - if (!help(parsedArgs, extraArgs)) { + if (!help(parsedArgs)) { const functionArgs = getFunctionArgs(parsedArgs, extraArgs); const client = deployClient ?? getDeployClient(); const address = await deployContract(functionArgs, client); @@ -49,13 +49,13 @@ function parseArgs(args: string[]) { return { parsedArgs, extraArgs }; } -function help(parsedArgs: minimist.ParsedArgs, extraArgs: string[]): boolean { - if (parsedArgs['help']) { +function help(parsedArgs: minimist.ParsedArgs): boolean { + if (!parsedArgs['help']) { + return false; + } else { console.log(USAGE); console.log(DETAILS); return true; - } else { - return false; } } diff --git a/src/commands/get-approval-process.ts b/src/commands/get-approval-process.ts index 224e46e..37f4cf2 100644 --- a/src/commands/get-approval-process.ts +++ b/src/commands/get-approval-process.ts @@ -26,7 +26,7 @@ export type Command = 'getDeployApprovalProcess' | 'getUpgradeApprovalProcess'; export async function getApprovalProcess(command: Command, args: string[], deployClient?: DeployClient): Promise { const { parsedArgs, extraArgs } = parseArgs(args); - if (!help(command, parsedArgs, extraArgs)) { + if (!help(command, parsedArgs)) { const network = getFunctionArgs(command, parsedArgs, extraArgs); const client = deployClient ?? getDeployClient(); @@ -64,8 +64,10 @@ function parseArgs(args: string[]) { return { parsedArgs, extraArgs }; } -function help(command: Command, parsedArgs: minimist.ParsedArgs, extraArgs: string[]): boolean { - if (parsedArgs['help']) { +function help(command: Command, parsedArgs: minimist.ParsedArgs): boolean { + if (!parsedArgs['help']) { + return false; + } else { switch (command) { case 'getDeployApprovalProcess': console.log(USAGE_DEPLOY); @@ -79,8 +81,6 @@ function help(command: Command, parsedArgs: minimist.ParsedArgs, extraArgs: stri throw new Error(`Unknown command: ${command}`); } return true; - } else { - return false; } } diff --git a/src/commands/propose-upgrade.ts b/src/commands/propose-upgrade.ts index 7b6efb6..0e67008 100644 --- a/src/commands/propose-upgrade.ts +++ b/src/commands/propose-upgrade.ts @@ -22,7 +22,7 @@ Additional options: export async function proposeUpgrade(args: string[], deployClient?: DeployClient): Promise { const { parsedArgs, extraArgs } = parseArgs(args); - if (!help(parsedArgs, extraArgs)) { + if (!help(parsedArgs)) { const functionArgs = getFunctionArgs(parsedArgs, extraArgs); const client = deployClient ?? getDeployClient(); const upgradeResponse = await upgradeContract(functionArgs, client); @@ -47,13 +47,13 @@ function parseArgs(args: string[]) { return { parsedArgs, extraArgs }; } -function help(parsedArgs: minimist.ParsedArgs, extraArgs: string[]): boolean { - if (parsedArgs['help']) { +function help(parsedArgs: minimist.ParsedArgs): boolean { + if (!parsedArgs['help']) { + return false; + } else { console.log(USAGE); console.log(DETAILS); return true; - } else { - return false; } }