|
1 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public
|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
4 |
| -import { Flags } from '@oclif/core' |
| 4 | +import chalk from 'chalk' |
5 | 5 | import { IronfishCommand } from '../../command'
|
6 |
| -import { RemoteFlags } from '../../flags' |
| 6 | +import { JsonFlags, RemoteFlags } from '../../flags' |
| 7 | +import * as ui from '../../ui' |
7 | 8 |
|
8 | 9 | export class AccountsCommand extends IronfishCommand {
|
9 | 10 | static description = `list accounts in the wallet`
|
| 11 | + static enableJsonFlag = true |
10 | 12 |
|
11 | 13 | static hiddenAliases = ['wallet:accounts']
|
12 | 14 |
|
13 | 15 | static flags = {
|
14 | 16 | ...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, |
19 | 19 | }
|
20 | 20 |
|
21 |
| - async start(): Promise<void> { |
| 21 | + async start(): Promise<unknown> { |
22 | 22 | const { flags } = await this.parse(AccountsCommand)
|
23 | 23 |
|
24 | 24 | const client = await this.connectRpc()
|
25 | 25 |
|
26 |
| - const response = await client.wallet.getAccounts({ displayName: flags.displayName }) |
| 26 | + const response = await client.wallet.getAccountsStatus() |
27 | 27 |
|
28 | 28 | if (response.content.accounts.length === 0) {
|
29 | 29 | this.log('you have no accounts')
|
| 30 | + return [] |
30 | 31 | }
|
31 | 32 |
|
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 |
35 | 75 | }
|
36 | 76 | }
|
0 commit comments