-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from armada-network/keydesc
Support optional key description
- Loading branch information
Showing
6 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Command } from "@oclif/core"; | ||
import { Arg } from "@oclif/core/lib/interfaces"; | ||
import inquirer from "inquirer"; | ||
import { listWallets, loadWallet, readWallet, updateWallet } from "../../keystore"; | ||
|
||
export default class KeyEdit extends Command { | ||
static description = "Changes the optional key description."; | ||
static examples = ["<%= config.bin %> <%= command.id %>"]; | ||
static usage = "<%= command.id %>"; | ||
static args: Arg[] = [ | ||
{ name: "ADDR", description: "The address of the key to describe." }, | ||
{ name: "DESC", description: "The new description for the key." }, | ||
]; | ||
|
||
public async run(): Promise<void> { | ||
const { args } = await this.parse(KeyEdit); | ||
if (!!args.ADDR !== !!args.DESC) { | ||
this.error("ADDR and DESC must be specified together"); | ||
} | ||
|
||
if (!args.ADDR) { | ||
const wallets = await listWallets(); | ||
if (!wallets.length) { | ||
throw Error("Error: No private keys found."); | ||
} | ||
|
||
const res1 = await inquirer.prompt({ | ||
name: "address", | ||
message: "Pick the account to describe:", | ||
type: "list", | ||
choices: wallets.map((w) => ({ | ||
value: w.address, | ||
name: w.description ? `${w.address} - ${w.description}` : w.address, | ||
})), | ||
}); | ||
|
||
const json = await readWallet(res1.address); | ||
const res2 = await inquirer.prompt({ | ||
name: "description", | ||
message: "Enter the key description:", | ||
default: json.description, | ||
}); | ||
|
||
args.ADDR = res1.address; | ||
args.DESC = res2.description; | ||
} | ||
|
||
const address = args.ADDR; | ||
await updateWallet(address, args.DESC); | ||
console.log(`Account ${address} updated`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters