Skip to content

Commit abbf3f9

Browse files
authored
Add table output to wallet command (#5265)
This adds optional new table output to the wallet command
1 parent 4f39cbc commit abbf3f9

File tree

1 file changed

+51
-11
lines changed
  • ironfish-cli/src/commands/wallet

1 file changed

+51
-11
lines changed
Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,76 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
import { Flags } from '@oclif/core'
4+
import chalk from 'chalk'
55
import { IronfishCommand } from '../../command'
6-
import { RemoteFlags } from '../../flags'
6+
import { JsonFlags, RemoteFlags } from '../../flags'
7+
import * as ui from '../../ui'
78

89
export class AccountsCommand extends IronfishCommand {
910
static description = `list accounts in the wallet`
11+
static enableJsonFlag = true
1012

1113
static hiddenAliases = ['wallet:accounts']
1214

1315
static flags = {
1416
...RemoteFlags,
15-
displayName: Flags.boolean({
16-
default: false,
17-
description: `Display a hash of the account's read-only keys along with the account name`,
18-
}),
17+
...JsonFlags,
18+
...ui.TableFlags,
1919
}
2020

21-
async start(): Promise<void> {
21+
async start(): Promise<unknown> {
2222
const { flags } = await this.parse(AccountsCommand)
2323

2424
const client = await this.connectRpc()
2525

26-
const response = await client.wallet.getAccounts({ displayName: flags.displayName })
26+
const response = await client.wallet.getAccountsStatus()
2727

2828
if (response.content.accounts.length === 0) {
2929
this.log('you have no accounts')
30+
return []
3031
}
3132

32-
for (const name of response.content.accounts) {
33-
this.log(name)
34-
}
33+
ui.table(
34+
response.content.accounts,
35+
{
36+
name: {
37+
get: (row) => row.name,
38+
header: 'Account',
39+
minWidth: 11,
40+
},
41+
viewOnly: {
42+
get: (row) => (row.viewOnly ? chalk.green('✓') : ''),
43+
header: 'View Only',
44+
extended: true,
45+
},
46+
headInChain: {
47+
get: (row) => (row.head?.inChain ? chalk.green('✓') : ''),
48+
header: 'In Chain',
49+
extended: true,
50+
},
51+
scanningEnabled: {
52+
get: (row) => (row.scanningEnabled ? chalk.green('✓') : ''),
53+
header: 'Scanning',
54+
extended: true,
55+
},
56+
sequence: {
57+
get: (row) => row.head?.sequence ?? '',
58+
header: 'Sequence',
59+
extended: true,
60+
},
61+
headHash: {
62+
get: (row) => row.head?.hash ?? '',
63+
header: 'Head',
64+
extended: true,
65+
},
66+
},
67+
{
68+
...flags,
69+
printLine: this.log.bind(this),
70+
'no-header': flags['no-header'] ?? !flags.extended,
71+
},
72+
)
73+
74+
return response.content.accounts
3575
}
3676
}

0 commit comments

Comments
 (0)