Skip to content

Commit

Permalink
Migrate from deprecated cli-ux to @oclif/core (#969)
Browse files Browse the repository at this point in the history
* Add @oclif/core package

* Migrate peers:list command from cli-ux to @oclif/core

* Migrate miners:mined command from cli-ux to @oclif/core

* Migrate chain:export command from cli-ux to @oclif/core

* Migrate chain:readdblock command from cli-ux to @oclif/core

* Migrate accounts:rescan command from cli-ux to @oclif/core

* Migrate backup command from cli-ux to @oclif/core

* Migrate restore command from cli-ux to @oclif/core

* Migrate accounts:export command from cli-ux to @oclif/core

* Migrate accounts:import command from cli-ux to @oclif/core

* Migrate accounts:create command from cli-ux to @oclif/core

* Migrate accounts:remove command from cli-ux to @oclif/core

* Migrate faucet command from cli-ux to @oclif/core

* Migrate accounts:pay command from cli-ux to @oclif/core

* Migrate chain:repair command from cli-ux to @oclif/core

* Migrate swim command from breaststroke to freestyle

* Migrate testnet command from cli-ux to @oclif/core

* Migrate reset command from cli-ux to @oclif/core

* Migrate miners:start command from cli-ux to @oclif/core

* Remove cli-ux package from project

* Fix of linter errors: import order mostly and row complexity sometimes
  • Loading branch information
Kupuyc committed Feb 10, 2022
1 parent 1ee07b3 commit 3e13335
Show file tree
Hide file tree
Showing 24 changed files with 215 additions and 117 deletions.
2 changes: 1 addition & 1 deletion ironfish-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"dependencies": {
"@oclif/command": "1.8.0",
"@oclif/config": "1.17.0",
"@oclif/core": "1.3.1",
"@oclif/plugin-help": "3.2.2",
"@oclif/plugin-not-found": "1.2.4",
"axios": "0.21.4",
"blessed": "0.1.81",
"cli-ux": "^5.5.0",
"ironfish": "*",
"ironfish-rust-nodejs": "*",
"json-colorizer": "2.2.2",
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/accounts/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { CliUx } from '@oclif/core'
import { expect as expectCli, test } from '@oclif/test'
import cli from 'cli-ux'
import * as ironfishmodule from 'ironfish'

describe('accounts:create command', () => {
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('accounts:create command', () => {
})

test
.stub(cli, 'prompt', () => async () => await Promise.resolve(name))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve(name))
.stdout()
.command(['accounts:create'])
.exit(0)
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/accounts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import cli from 'cli-ux'
import { CliUx } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

Expand All @@ -27,7 +27,7 @@ export class CreateCommand extends IronfishCommand {
let name = args.name as string

if (!name) {
name = (await cli.prompt('Enter the name of the account', {
name = (await CliUx.ux.prompt('Enter the name of the account', {
required: true,
})) as string
}
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/accounts/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { flags } from '@oclif/command'
import cli from 'cli-ux'
import { CliUx } from '@oclif/core'
import fs from 'fs'
import { ErrorUtils } from 'ironfish'
import jsonColorizer from 'json-colorizer'
Expand Down Expand Up @@ -61,7 +61,7 @@ export class ExportCommand extends IronfishCommand {
if (fs.existsSync(resolved)) {
this.log(`There is already an account backup at ${exportPath}`)

const confirmed = await cli.confirm(
const confirmed = await CliUx.ux.confirm(
`\nOverwrite the account backup with new file?\nAre you sure? (Y)es / (N)o`,
)

Expand Down
12 changes: 6 additions & 6 deletions ironfish-cli/src/commands/accounts/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { flags } from '@oclif/command'
import { cli } from 'cli-ux'
import { CliUx } from '@oclif/core'
import { JSONUtils, PromiseUtils, SerializedAccount } from 'ironfish'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
Expand Down Expand Up @@ -89,23 +89,23 @@ export class ImportCommand extends IronfishCommand {
}

async importTTY(): Promise<SerializedAccount> {
const accountName = (await cli.prompt('Enter the account name', {
const accountName = (await CliUx.ux.prompt('Enter the account name', {
required: true,
})) as string

const spendingKey = (await cli.prompt('Enter the account spending key', {
const spendingKey = (await CliUx.ux.prompt('Enter the account spending key', {
required: true,
})) as string

const incomingViewKey = (await cli.prompt('Enter the account incoming view key', {
const incomingViewKey = (await CliUx.ux.prompt('Enter the account incoming view key', {
required: true,
})) as string

const outgoingViewKey = (await cli.prompt('Enter the account outgoing view key', {
const outgoingViewKey = (await CliUx.ux.prompt('Enter the account outgoing view key', {
required: true,
})) as string

const publicAddress = (await cli.prompt('Enter the account public address', {
const publicAddress = (await CliUx.ux.prompt('Enter the account public address', {
required: true,
})) as string

Expand Down
28 changes: 14 additions & 14 deletions ironfish-cli/src/commands/accounts/pay.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { CliUx } from '@oclif/core'
import { expect as expectCli, test } from '@oclif/test'
import cli from 'cli-ux'
import * as ironfishmodule from 'ironfish'

describe('accounts:pay command', () => {
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('accounts:pay command', () => {
})

test
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command([
'accounts:pay',
Expand All @@ -79,7 +79,7 @@ describe('accounts:pay command', () => {
)

test
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command(['accounts:pay', `-a ${amount}`, `-t ${to}`, `-f ${from}`, `-o ${fee}`])
.exit(0)
Expand All @@ -95,8 +95,8 @@ describe('accounts:pay command', () => {
)

test
.stub(cli, 'prompt', () => async () => await Promise.resolve(to))
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve(to))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command(['accounts:pay', `-a ${amount}`, `-f ${from}`, `-o ${fee}`])
.exit(0)
Expand All @@ -109,8 +109,8 @@ describe('accounts:pay command', () => {
)

test
.stub(cli, 'prompt', () => async () => await Promise.resolve('not correct address'))
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve('not correct address'))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command(['accounts:pay', `-a ${amount}`, `-f ${from}`])
.exit(2)
Expand All @@ -119,8 +119,8 @@ describe('accounts:pay command', () => {
})

test
.stub(cli, 'prompt', () => async () => await Promise.resolve(3))
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve(3))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command(['accounts:pay', `-t ${to}`, `-f ${from}`])
.exit(0)
Expand All @@ -136,8 +136,8 @@ describe('accounts:pay command', () => {
)

test
.stub(cli, 'prompt', () => async () => await Promise.resolve('non right value'))
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve('non right value'))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command(['accounts:pay', `-t ${to}`, `-f ${from}`])
.exit(0)
Expand All @@ -146,7 +146,7 @@ describe('accounts:pay command', () => {
})

test
.stub(cli, 'confirm', () => async () => await Promise.resolve(false))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(false))
.stdout()
.command(['accounts:pay', `-a ${amount}`, `-t ${to}`, `-f ${from}`, `-o ${fee}`])
.exit(0)
Expand All @@ -156,7 +156,7 @@ describe('accounts:pay command', () => {

describe('with an invalid expiration sequence', () => {
test
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command([
'accounts:pay',
Expand All @@ -179,7 +179,7 @@ describe('accounts:pay command', () => {
sendTransaction = jest.fn().mockRejectedValue('an error')
})
test
.stub(cli, 'confirm', () => async () => await Promise.resolve(true))
.stub(CliUx.ux, 'confirm', () => async () => await Promise.resolve(true))
.stdout()
.command(['accounts:pay', `-a ${amount}`, `-t ${to}`, `-f ${from}`, `-o ${fee}`])
.exit(2)
Expand Down
12 changes: 6 additions & 6 deletions ironfish-cli/src/commands/accounts/pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { flags } from '@oclif/command'
import cli from 'cli-ux'
import { CliUx } from '@oclif/core'
import {
displayIronAmountWithCurrency,
ironToOre,
Expand Down Expand Up @@ -81,7 +81,7 @@ export class Pay extends IronfishCommand {
if (!amount || Number.isNaN(amount)) {
const response = await client.getAccountBalance({ account: from })

amount = (await cli.prompt(
amount = (await CliUx.ux.prompt(
`Enter the amount in $IRON (balance available: ${displayIronAmountWithCurrency(
oreToIron(Number(response.content.confirmed)),
false,
Expand All @@ -97,7 +97,7 @@ export class Pay extends IronfishCommand {
}

if (!fee || Number.isNaN(Number(fee))) {
fee = (await cli.prompt('Enter the fee amount in $IRON', {
fee = (await CliUx.ux.prompt('Enter the fee amount in $IRON', {
required: true,
default: '0.00000001',
})) as number
Expand All @@ -108,7 +108,7 @@ export class Pay extends IronfishCommand {
}

if (!to) {
to = (await cli.prompt('Enter the the public address of the recipient', {
to = (await CliUx.ux.prompt('Enter the the public address of the recipient', {
required: true,
})) as string

Expand Down Expand Up @@ -170,7 +170,7 @@ ${displayIronAmountWithCurrency(
* This action is NOT reversible *
`)

const confirm = await cli.confirm('Do you confirm (Y/N)?')
const confirm = await CliUx.ux.confirm('Do you confirm (Y/N)?')
if (!confirm) {
this.log('Transaction aborted.')
this.exit(0)
Expand All @@ -179,7 +179,7 @@ ${displayIronAmountWithCurrency(

// Run the progress bar for about 2 minutes
// Chances are that the transaction will finish faster (error or faster computer)
const bar = cli.progress({
const bar = CliUx.ux.progress({
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
format: 'Creating the transaction: [{bar}] {percentage}% | ETA: {eta}s',
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/src/commands/accounts/remove.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { CliUx } from '@oclif/core'
import { expect as expectCli, test } from '@oclif/test'
import cli from 'cli-ux'
import * as ironfish from 'ironfish'

describe('accounts:remove', () => {
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('accounts:remove', () => {

describe('with no flags', () => {
test
.stub(cli, 'prompt', () => async () => await Promise.resolve(name))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve(name))
.stdout()
.command(['accounts:remove', name])
.exit(0)
Expand All @@ -47,7 +47,7 @@ describe('accounts:remove', () => {
const incorrectName = 'foobar'

test
.stub(cli, 'prompt', () => async () => await Promise.resolve(incorrectName))
.stub(CliUx.ux, 'prompt', () => async () => await Promise.resolve(incorrectName))
.stdout()
.command(['accounts:remove', name])
.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/accounts/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { flags } from '@oclif/command'
import { cli } from 'cli-ux'
import { CliUx } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

Expand Down Expand Up @@ -35,7 +35,7 @@ export class RemoveCommand extends IronfishCommand {
const response = await client.removeAccount({ name, confirm })

if (response.content.needsConfirm) {
const value = (await cli.prompt(`Are you sure? Type ${name} to confirm`)) as string
const value = (await CliUx.ux.prompt(`Are you sure? Type ${name} to confirm`)) as string

if (value !== name) {
this.log(`Aborting: ${value} did not match ${name}`)
Expand Down
10 changes: 5 additions & 5 deletions ironfish-cli/src/commands/accounts/rescan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { flags } from '@oclif/command'
import cli from 'cli-ux'
import { CliUx } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
import { hasUserResponseError } from '../../utils'
Expand Down Expand Up @@ -32,27 +32,27 @@ export class RescanCommand extends IronfishCommand {
const { detach, reset, local } = flags
const client = await this.sdk.connectRpc(local)

cli.action.start('Rescanning Transactions', 'Asking node to start scanning', {
CliUx.ux.action.start('Rescanning Transactions', 'Asking node to start scanning', {
stdout: true,
})

const response = client.rescanAccountStream({ reset, follow: !detach })

try {
for await (const { sequence, startedAt } of response.contentStream()) {
cli.action.status = `Scanning Block: ${sequence}, ${Math.floor(
CliUx.ux.action.status = `Scanning Block: ${sequence}, ${Math.floor(
(Date.now() - startedAt) / 1000,
)} seconds`
}
} catch (error) {
if (hasUserResponseError(error)) {
cli.action.stop(error.codeMessage)
CliUx.ux.action.stop(error.codeMessage)
return
}

throw error
}

cli.action.stop(detach ? 'Scan started in background' : 'Scanning Complete')
CliUx.ux.action.stop(detach ? 'Scan started in background' : 'Scanning Complete')
}
}
10 changes: 5 additions & 5 deletions ironfish-cli/src/commands/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { flags } from '@oclif/command'
import { CliUx } from '@oclif/core'
import { spawn } from 'child_process'
import cli from 'cli-ux'
import fsAsync from 'fs/promises'
import { FileUtils, NodeUtils } from 'ironfish'
import os from 'os'
Expand Down Expand Up @@ -59,7 +59,7 @@ export default class Backup extends IronfishCommand {
const dest = path.join(destDir, `node.${id}.tar.gz`)

this.log(`Zipping\n SRC ${source}\n DST ${dest}\n`)
cli.action.start(`Zipping ${source}`)
CliUx.ux.action.start(`Zipping ${source}`)

await this.zipDir(
source,
Expand All @@ -68,11 +68,11 @@ export default class Backup extends IronfishCommand {
)

const stat = await fsAsync.stat(dest)
cli.action.stop(`done (${FileUtils.formatFileSize(stat.size)})`)
CliUx.ux.action.stop(`done (${FileUtils.formatFileSize(stat.size)})`)

cli.action.start(`Uploading to ${bucket}`)
CliUx.ux.action.start(`Uploading to ${bucket}`)
await this.uploadToS3(dest, bucket)
cli.action.stop(`done`)
CliUx.ux.action.stop(`done`)
}

zipDir(source: string, dest: string, excludes: string[] = []): Promise<number | null> {
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/chain/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { flags } from '@oclif/command'
import cli from 'cli-ux'
import { CliUx } from '@oclif/core'
import fs from 'fs'
import { AsyncUtils, GENESIS_BLOCK_SEQUENCE } from 'ironfish'
import { parseNumber } from '../../args'
Expand Down Expand Up @@ -54,7 +54,7 @@ export default class Export extends IronfishCommand {
const { start, stop } = await AsyncUtils.first(stream.contentStream())
this.log(`Exporting chain from ${start} -> ${stop} to ${path}`)

const progress = cli.progress({
const progress = CliUx.ux.progress({
format: 'Exporting blocks: [{bar}] {value}/{total} {percentage}% | ETA: {eta}s',
}) as ProgressBar

Expand Down

0 comments on commit 3e13335

Please sign in to comment.