/
remove-wallet.js
51 lines (37 loc) · 1.09 KB
/
remove-wallet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const shelljs = require('shelljs')
const { Command, flags } = require('@oclif/command')
class RemoveWallet extends Command {
async run () {
try {
const { flags } = this.parse(RemoveWallet)
// Validate input flags
this.validateFlags(flags)
const filename = `${__dirname.toString()}/../../wallets/${
flags.name
}.json`
return this.removeWallet(filename)
} catch (err) {
console.log('Error: ', err)
}
}
async removeWallet (filename) {
const result = shelljs.rm(filename)
if (!shelljs.error()) return result
throw new Error(result.stderr || 'Error in removeWallet().')
}
// Validate the proper flags are passed in.
validateFlags (flags) {
// Exit if wallet not specified.
const name = flags.name
if (!name || name === '') {
throw new Error('You must specify a wallet with the -n flag.')
}
return true
}
}
RemoveWallet.description = 'Remove an existing wallet.'
RemoveWallet.flags = {
name: flags.string({ char: 'n', description: 'Name of wallet' })
}
module.exports = RemoveWallet