@@ -22,6 +22,7 @@ import {
22
22
ImportOption ,
23
23
ListOption
24
24
} from "./types" ;
25
+ import { getAddressFromKey } from "./util" ;
25
26
26
27
const VERSION = "0.3.0" ;
27
28
@@ -134,8 +135,11 @@ async function createCommand(args: any[], option: CreateOption) {
134
135
async function deleteCommand ( args : any [ ] , option : DeleteOption ) {
135
136
const cckey = await CCKey . create ( { dbPath : option . parent . keysPath } ) ;
136
137
const accountType = parseAccountType ( option . parent . accountType ) ;
137
- const address = parseAddress ( accountType , option . address ) ;
138
138
const networkId = option . parent . networkId ;
139
+ if ( _ . isUndefined ( option . address ) && process . stdout . isTTY ) {
140
+ option . address = await selectAddress ( cckey , networkId , accountType ) ;
141
+ }
142
+ const address = parseAddress ( accountType , option . address ) ;
139
143
await deleteKey (
140
144
{
141
145
cckey,
@@ -182,9 +186,12 @@ async function importRawCommand([privateKey]: any[], option: ImportOption) {
182
186
async function exportCommand ( args : any [ ] , option : ExportOption ) {
183
187
const cckey = await CCKey . create ( { dbPath : option . parent . keysPath } ) ;
184
188
const accountType = parseAccountType ( option . parent . accountType ) ;
189
+ const networkId = option . parent . networkId ;
190
+ if ( _ . isUndefined ( option . address ) && process . stdout . isTTY ) {
191
+ option . address = await selectAddress ( cckey , networkId , accountType ) ;
192
+ }
185
193
const address = parseAddress ( accountType , option . address ) ;
186
194
const passphrase = await parsePassphrase ( option . passphrase ) ;
187
- const networkId = option . parent . networkId ;
188
195
const secret = await exportKey (
189
196
{
190
197
cckey,
@@ -274,3 +281,24 @@ async function parsePassphrase(passphrase: string): Promise<string> {
274
281
}
275
282
return answers . passphrase;
276
283
}
284
+
285
+ async function selectAddress (
286
+ cckey : CCKey ,
287
+ networkId : string ,
288
+ accountType : AccountType
289
+ ) : Promise < string > {
290
+ const Enquirer = require ( "enquirer" ) ;
291
+ const enquirer = new Enquirer ( ) ;
292
+ enquirer . register ( "list" , require ( "prompt-list" ) ) ;
293
+
294
+ let keys = await cckey [ accountType ] . getKeys ( ) ;
295
+ keys = _ . map ( keys , key => getAddressFromKey ( accountType , key , networkId ) ) ;
296
+ const questions = {
297
+ type : "list" ,
298
+ name : "address" ,
299
+ message : "Select your address please" ,
300
+ choices : keys
301
+ } ;
302
+ const answers = await enquirer . ask ( questions ) ;
303
+ return answers . address ;
304
+ }
0 commit comments