Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #100 from mesg-foundation/ux/command-account
Browse files Browse the repository at this point in the history
Improve ux of account commands
  • Loading branch information
antho1404 authored Jul 8, 2019
2 parents 2a5b820 + 7140598 commit 5811ced
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
9 changes: 3 additions & 6 deletions src/account-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ export abstract class WithPassphrase extends WithoutPassphrase {
static flags = {
...WithoutPassphrase.flags,
passphrase: flags.string({
description: 'Passphrase to unlock your account'
description: 'Passphrase of the account'
})
}

async getPassphrase(): Promise<string | null> {
const {flags} = this.parse()
if (flags.passphrase) {
return flags.passphrase
}
const passphrase = await cli.prompt('Type your passphrase', {type: 'hide'})
return passphrase
if (flags.passphrase) return flags.passphrase
return cli.prompt('Type the passphrase', {type: 'hide'})
}
}
9 changes: 4 additions & 5 deletions src/commands/account/create.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountCreate extends Command {
static description = 'Create a new account'
static description = 'Create an account'

static flags = {
...Command.flags,
}

async run() {
this.spinner.start('Create account')
const passphrase = await this.getPassphrase()
this.spinner.start('Creating account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'create',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
})
inputs: JSON.stringify({passphrase})
})
this.spinner.stop(data.address)
return data
Expand Down
10 changes: 5 additions & 5 deletions src/commands/account/delete.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountDelete extends Command {
static description = 'Delete an existing account'
static description = 'Delete an account'

static flags = {
...Command.flags,
Expand All @@ -14,17 +14,17 @@ export default class AccountDelete extends Command {

async run() {
const {args} = this.parse(AccountDelete)

this.spinner.start('Delete account')
const passphrase = await this.getPassphrase()
this.spinner.start('Deleting account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'delete',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
address: args.ADDRESS,
passphrase
})
})
this.spinner.stop(data.address)
this.spinner.stop()
return data
}
}
6 changes: 3 additions & 3 deletions src/commands/account/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default class AccountExport extends Command {

async run() {
const {args} = this.parse(AccountExport)

this.spinner.start('Export account')
const passphrase = await this.getPassphrase()
this.spinner.start('Exporting account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'export',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
address: args.ADDRESS,
passphrase,
})
})
this.spinner.stop()
Expand Down
10 changes: 5 additions & 5 deletions src/commands/account/import-private-key.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountImportPK extends Command {
static description = 'Import a account from a private key'
static description = 'Import an account with a private key'

static flags = {
...Command.flags,
}

static args = [{
name: 'PRIVATE_KEY',
description: 'Private key for your account',
description: 'Private key of the account',
required: true,
}]

async run() {
const {args} = this.parse(AccountImportPK)

this.spinner.start('Import account')
const passphrase = await this.getPassphrase()
this.spinner.start('Importing account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'importFromPrivateKey',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
privateKey: args.PRIVATE_KEY,
passphrase,
})
})
this.spinner.stop(data.address)
Expand Down
10 changes: 5 additions & 5 deletions src/commands/account/import.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import {WithPassphrase as Command} from '../../account-command'

export default class AccountImport extends Command {
static description = 'Import a account'
static description = 'Import an account'

static flags = {
...Command.flags,
}

static args = [{
name: 'ACCOUNT',
description: 'Account saved from a previous account',
description: 'Account definition in JSON (could be retrieved with account:export)',
required: true
}]

async run() {
const {args} = this.parse(AccountImport)

this.spinner.start('Import account')
const passphrase = await this.getPassphrase()
this.spinner.start('Importing account')
const data = await this.execute({
instanceHash: await this.engineServiceInstance(Command.SERVICE_NAME),
taskKey: 'import',
inputs: JSON.stringify({
passphrase: await this.getPassphrase(),
account: JSON.parse(args.ACCOUNT),
passphrase,
})
})
this.spinner.stop(data.address)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/account/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {cli} from 'cli-ux'
import {WithoutPassphrase as Command} from '../../account-command'

export default class AccountList extends Command {
static description = 'List all existing accounts'
static description = 'List accounts'

static flags = {
...Command.flags,
Expand Down

0 comments on commit 5811ced

Please sign in to comment.