Skip to content

Commit

Permalink
Rename Format -> TableOutput and output -> Format
Browse files Browse the repository at this point in the history
This clarifies the names and keeps them consistent with the table
naming.
  • Loading branch information
NullSoldier committed Nov 13, 2024
1 parent 5cc13d7 commit 08289de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
42 changes: 21 additions & 21 deletions ironfish-cli/src/commands/wallet/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand All @@ -67,14 +67,14 @@ export class TransactionsCommand extends IronfishCommand {
async start(): Promise<void> {
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'
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -148,8 +148,8 @@ export class TransactionsCommand extends IronfishCommand {
assetLookup,
accountsByAddress,
transaction,
format,
output,
format,
),
)
} else {
Expand All @@ -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),
Expand Down Expand Up @@ -208,7 +208,7 @@ export class TransactionsCommand extends IronfishCommand {
getTransactionRows(
assetLookup: { [key: string]: RpcAsset },
transaction: GetAccountTransactionsResponse,
format: Format,
output: TableOutput,
): PartialRecursive<TransactionRow>[] {
const nativeAssetId = Asset.nativeId().toString('hex')

Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -269,8 +269,8 @@ export class TransactionsCommand extends IronfishCommand {
assetLookup: { [key: string]: RpcAsset },
accountLookup: Map<string, string>,
transaction: GetAccountTransactionsResponse,
format: Format,
output: 'notes' | 'transactions' | 'transfers',
output: TableOutput,
format: 'notes' | 'transactions' | 'transfers',
): PartialRecursive<TransactionRow>[] {
Assert.isNotUndefined(transaction.notes)
const transactionRows = []
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -345,7 +345,7 @@ export class TransactionsCommand extends IronfishCommand {
getColumns(
extended: boolean,
output: 'notes' | 'transactions' | 'transfers',
format: Format,
format: TableOutput,
): ui.TableColumns<PartialRecursive<TransactionRow>> {
let columns: ui.TableColumns<PartialRecursive<TransactionRow>> = {
timestamp: TableCols.timestamp({
Expand Down Expand Up @@ -443,7 +443,7 @@ export class TransactionsCommand extends IronfishCommand {
}
}

if (format === Format.cli) {
if (format === TableOutput.cli) {
columns = {
group: {
header: '',
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/ui/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/src/utils/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const timestamp = <T extends Record<string, unknown>>(options?: {

const asset = <T extends Record<string, unknown>>(options?: {
extended?: boolean
format?: Format
format?: TableOutput
}): Partial<Record<string, TableColumn<T>>> => {
if (options?.extended || options?.format !== Format.cli) {
if (options?.extended || options?.format !== TableOutput.cli) {
return {
assetId: {
header: 'Asset ID',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 08289de

Please sign in to comment.