From 08289de7491527263df1bd4c07e16836192eba5d Mon Sep 17 00:00:00 2001 From: Jason Spafford Date: Wed, 13 Nov 2024 14:37:59 -0800 Subject: [PATCH] Rename Format -> TableOutput and output -> Format This clarifies the names and keeps them consistent with the table naming. --- .../src/commands/wallet/transactions/index.ts | 42 +++++++++---------- ironfish-cli/src/ui/table.ts | 2 +- ironfish-cli/src/utils/table.ts | 6 +-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ironfish-cli/src/commands/wallet/transactions/index.ts b/ironfish-cli/src/commands/wallet/transactions/index.ts index f808efaffa..2bc52b5aec 100644 --- a/ironfish-cli/src/commands/wallet/transactions/index.ts +++ b/ironfish-cli/src/commands/wallet/transactions/index.ts @@ -18,7 +18,7 @@ import { RemoteFlags } from '../../../flags' import * as ui from '../../../ui' import { getAssetsByIDs, useAccount } from '../../../utils' import { extractChainportDataFromTransaction } from '../../../utils/chainport' -import { Format, TableCols } from '../../../utils/table' +import { TableCols, TableOutput } from '../../../utils/table' const { sort: _, ...tableFlags } = ui.TableFlags @@ -57,7 +57,7 @@ export class TransactionsCommand extends IronfishCommand { description: 'Include data from transaction output notes', }), format: Flags.string({ - description: 'output in a more machine friendly format', + description: 'show the data in a specified view', exclusive: ['notes'], options: ['notes', 'transactions', 'transfers'], helpGroup: 'OUTPUT', @@ -67,14 +67,14 @@ export class TransactionsCommand extends IronfishCommand { async start(): Promise { const { flags } = await this.parse(TransactionsCommand) - const format: Format = + const output: TableOutput = flags.csv || flags.output === 'csv' - ? Format.csv + ? TableOutput.csv : flags.output === 'json' - ? Format.json - : Format.cli + ? TableOutput.json + : TableOutput.cli - const output = + const format = flags.notes || flags.format === 'notes' ? 'notes' : flags.format === 'transactions' @@ -115,7 +115,7 @@ export class TransactionsCommand extends IronfishCommand { flags.limit, flags.offset, flags.confirmations, - output === 'notes' || output === 'transfers', + format === 'notes' || format === 'transfers', ) let hasTransactions = false @@ -126,7 +126,7 @@ export class TransactionsCommand extends IronfishCommand { break } - if (output === 'notes' || output === 'transfers') { + if (format === 'notes' || format === 'transfers') { Assert.isNotUndefined(transaction.notes) const assetLookup = await getAssetsByIDs( @@ -148,8 +148,8 @@ export class TransactionsCommand extends IronfishCommand { assetLookup, accountsByAddress, transaction, - format, output, + format, ), ) } else { @@ -160,13 +160,13 @@ export class TransactionsCommand extends IronfishCommand { flags.confirmations, ) transactionRows = transactionRows.concat( - this.getTransactionRows(assetLookup, transaction, format), + this.getTransactionRows(assetLookup, transaction, output), ) } hasTransactions = true } - const columns = this.getColumns(flags.extended, output, format) + const columns = this.getColumns(flags.extended, format, output) ui.table(transactionRows, columns, { printLine: this.log.bind(this), @@ -208,7 +208,7 @@ export class TransactionsCommand extends IronfishCommand { getTransactionRows( assetLookup: { [key: string]: RpcAsset }, transaction: GetAccountTransactionsResponse, - format: Format, + output: TableOutput, ): PartialRecursive[] { const nativeAssetId = Asset.nativeId().toString('hex') @@ -233,7 +233,7 @@ export class TransactionsCommand extends IronfishCommand { // exclude the native asset in cli output if no amount was sent/received // and it was not the only asset exchanged - if (format === Format.cli && amount === 0n && assetCount > 1) { + if (output === TableOutput.cli && amount === 0n && assetCount > 1) { assetCount -= 1 continue } @@ -251,7 +251,7 @@ export class TransactionsCommand extends IronfishCommand { } // include full transaction details in first row or non-cli-formatted output - if (transactionRows.length === 0 || format !== Format.cli) { + if (transactionRows.length === 0 || output !== TableOutput.cli) { transactionRows.push({ ...transaction, ...transactionRow, @@ -269,8 +269,8 @@ export class TransactionsCommand extends IronfishCommand { assetLookup: { [key: string]: RpcAsset }, accountLookup: Map, transaction: GetAccountTransactionsResponse, - format: Format, - output: 'notes' | 'transactions' | 'transfers', + output: TableOutput, + format: 'notes' | 'transactions' | 'transfers', ): PartialRecursive[] { Assert.isNotUndefined(transaction.notes) const transactionRows = [] @@ -297,7 +297,7 @@ export class TransactionsCommand extends IronfishCommand { let group = this.getRowGroup(index, noteCount, transactionRows.length) - if (output === 'transfers') { + if (format === 'transfers') { if (note.sender === note.owner && !transaction.mints.length) { continue } else { @@ -306,7 +306,7 @@ export class TransactionsCommand extends IronfishCommand { } // include full transaction details in first row or non-cli-formatted output - if (transactionRows.length === 0 || format !== Format.cli) { + if (transactionRows.length === 0 || output !== TableOutput.cli) { transactionRows.push({ ...transaction, group, @@ -345,7 +345,7 @@ export class TransactionsCommand extends IronfishCommand { getColumns( extended: boolean, output: 'notes' | 'transactions' | 'transfers', - format: Format, + format: TableOutput, ): ui.TableColumns> { let columns: ui.TableColumns> = { timestamp: TableCols.timestamp({ @@ -443,7 +443,7 @@ export class TransactionsCommand extends IronfishCommand { } } - if (format === Format.cli) { + if (format === TableOutput.cli) { columns = { group: { header: '', diff --git a/ironfish-cli/src/ui/table.ts b/ironfish-cli/src/ui/table.ts index d17345ee84..fd24116a9b 100644 --- a/ironfish-cli/src/ui/table.ts +++ b/ironfish-cli/src/ui/table.ts @@ -48,7 +48,7 @@ export const TableFlags = { helpGroup: 'OUTPUT', }), output: Flags.string({ - description: 'output in a more machine friendly format', + description: 'output in different file types', exclusive: ['csv'], options: ['csv', 'json'], helpGroup: 'OUTPUT', diff --git a/ironfish-cli/src/utils/table.ts b/ironfish-cli/src/utils/table.ts index 60220eb957..550b890beb 100644 --- a/ironfish-cli/src/utils/table.ts +++ b/ironfish-cli/src/utils/table.ts @@ -61,9 +61,9 @@ const timestamp = >(options?: { const asset = >(options?: { extended?: boolean - format?: Format + format?: TableOutput }): Partial>> => { - if (options?.extended || options?.format !== Format.cli) { + if (options?.extended || options?.format !== TableOutput.cli) { return { assetId: { header: 'Asset ID', @@ -127,7 +127,7 @@ function truncateCol(value: string, maxWidth: number | null): string { return value.slice(0, maxWidth - 1) + '…' } -export enum Format { +export enum TableOutput { cli = 'cli', csv = 'csv', json = 'json',