From fb4691b6582d130b894d21a40b3c9aecff2e27ff Mon Sep 17 00:00:00 2001 From: mixmix Date: Thu, 3 Oct 2024 13:33:08 +1300 Subject: [PATCH] fix cli opts bug with multiple accountOptions --- src/account/command.ts | 6 +++--- src/cli.ts | 4 +--- src/common/utils-cli.ts | 7 ++++--- src/sign/command.ts | 6 +++--- src/transfer/command.ts | 6 +++--- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/account/command.ts b/src/account/command.ts index a502a850..8447af16 100644 --- a/src/account/command.ts +++ b/src/account/command.ts @@ -4,7 +4,7 @@ import { EntropyAccount } from "./main"; import { selectAndPersistNewAccount, addVerifyingKeyToAccountAndSelect } from "./utils"; import { ACCOUNTS_CONTENT } from './constants' import * as config from '../config' -import { cliWrite, accountOption, endpointOption, loadEntropy, passwordOption } from "../common/utils-cli"; +import { accountOption, endpointOption, passwordOption, cliWrite, loadEntropy } from "../common/utils-cli"; export function entropyAccountCommand () { return new Command('account') @@ -84,9 +84,9 @@ function entropyAccountList () { function entropyAccountRegister () { return new Command('register') .description('Register an entropy account with a program') - .addOption(passwordOption()) - .addOption(endpointOption()) .addOption(accountOption()) + .addOption(endpointOption()) + .addOption(passwordOption()) // Removing these options for now until we update the design to accept program configs // .addOption( // new Option( diff --git a/src/cli.ts b/src/cli.ts index b531efa8..cc004d79 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -4,7 +4,7 @@ import { Command, Option } from 'commander' import { EntropyTuiOptions } from './types' -import { accountOption, endpointOption, loadEntropy } from './common/utils-cli' +import { loadEntropy } from './common/utils-cli' import * as config from './config' import launchTui from './tui' @@ -20,8 +20,6 @@ const program = new Command() program .name('entropy') .description('CLI interface for interacting with entropy.xyz. Running this binary without any commands or arguments starts a text-based interface.') - .addOption(accountOption()) - .addOption(endpointOption()) .addOption( new Option( '-d, --dev', diff --git a/src/common/utils-cli.ts b/src/common/utils-cli.ts index 3aec350b..00fc8c34 100644 --- a/src/common/utils-cli.ts +++ b/src/common/utils-cli.ts @@ -20,7 +20,7 @@ function getConfigOrNull () { export function endpointOption () { return new Option( - '-e, --endpoint ', + '-e, --endpoint ', [ 'Runs entropy with the given endpoint and ignores network endpoints in config.', 'Can also be given a stored endpoint name from config eg: `entropy --endpoint test-net`.' @@ -44,16 +44,17 @@ export function endpointOption () { export function passwordOption (description?: string) { return new Option( - '-p, --password ', + '-p, --password ', description || 'Password for the account' ) + .hideHelp(true) } export function accountOption () { const storedConfig = getConfigOrNull() return new Option( - '-a, --account ', + '-a, --account ', [ 'Sets the account for the session.', 'Defaults to the last set account (or the first account if one has not been set before).' diff --git a/src/sign/command.ts b/src/sign/command.ts index fc574228..1c67f4d6 100644 --- a/src/sign/command.ts +++ b/src/sign/command.ts @@ -1,14 +1,14 @@ import { Command, /* Option */ } from 'commander' -import { cliWrite, accountOption, endpointOption, loadEntropy, passwordOption } from '../common/utils-cli' +import { accountOption, endpointOption, passwordOption, cliWrite, loadEntropy } from '../common/utils-cli' import { EntropySign } from './main' export function entropySignCommand () { const signCommand = new Command('sign') .description('Sign a message using the Entropy network. Output is a JSON { verifyingKey, signature }') .argument('msg', 'Message you would like to sign (string)') - .addOption(passwordOption('Password for the source account (if required)')) - .addOption(endpointOption()) .addOption(accountOption()) + .addOption(endpointOption()) + .addOption(passwordOption('Password for the source account (if required)')) // .addOption( // new Option( // '-r, --raw', diff --git a/src/transfer/command.ts b/src/transfer/command.ts index b814e2f9..e8ef3ceb 100644 --- a/src/transfer/command.ts +++ b/src/transfer/command.ts @@ -1,5 +1,5 @@ import { Command } from "commander" -import { accountOption, endpointOption, loadEntropy, passwordOption } from "src/common/utils-cli" +import { accountOption, endpointOption, passwordOption, loadEntropy } from "../common/utils-cli" import { EntropyTransfer } from "./main" export function entropyTransferCommand () { @@ -8,9 +8,9 @@ export function entropyTransferCommand () { .description('Transfer funds between two Entropy accounts.') // TODO: name the output .argument('destination', 'Account address funds will be sent to') .argument('amount', 'Amount of funds to be moved') - .addOption(passwordOption('Password for the source account (if required)')) - .addOption(endpointOption()) .addOption(accountOption()) + .addOption(endpointOption()) + .addOption(passwordOption('Password for the source account (if required)')) .action(async (destination, amount, opts) => { const entropy = await loadEntropy(opts.account, opts.endpoint) const transferService = new EntropyTransfer(entropy, opts.endpoint)