Skip to content

Commit f97d9eb

Browse files
committed
Make account-type option a common option
1 parent 2b9740a commit f97d9eb

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

src/index.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,34 @@ import {
2121

2222
const VERSION = "0.1.1";
2323

24-
program.version(VERSION);
25-
2624
program
27-
.command("list")
28-
.description("list keys")
25+
.version(VERSION)
2926
.option(
3027
"-t, --account-type <accountType>",
3128
"'platform' or 'asset'. The type of the key",
3229
"platform"
33-
)
30+
);
31+
32+
program
33+
.command("list")
34+
.description("list keys")
3435
.action(handleError(listCommand));
3536

3637
program
3738
.command("create")
3839
.description("create a new key")
39-
.option(
40-
"-t, --account-type <accountType>",
41-
"'platform' or 'asset'. The type of the key",
42-
"platform"
43-
)
4440
.option("-p, --passphrase <passphrase>", "passphrase")
4541
.action(handleError(createCommand));
4642

4743
program
4844
.command("delete")
4945
.description("delete the key")
50-
.option(
51-
"-t, --account-type <accountType>",
52-
"'platform' or 'asset'. The type of the key",
53-
"platform"
54-
)
5546
.option("-a, --address <address>", "address")
5647
.action(handleError(deleteCommand));
5748

5849
program
5950
.command("import <path>")
6051
.description("import a key")
61-
.option(
62-
"-t, --account-type <accountType>",
63-
"'platform' or 'asset'. The type of the key",
64-
"platform"
65-
)
6652
.option("-p, --passphrase <passphrase>", "passphrase")
6753
.action(handleError(importCommand));
6854

@@ -81,27 +67,27 @@ function handleError(
8167

8268
async function listCommand(option: ListOption) {
8369
const cckey = await CCKey.create();
84-
const accountType = parseAccountType(option.accountType);
70+
const accountType = parseAccountType(option.parent.accountType);
8571
await listKeys(cckey, accountType);
8672
}
8773

8874
async function createCommand(option: CreateOption) {
8975
const cckey = await CCKey.create();
90-
const accountType = parseAccountType(option.accountType);
76+
const accountType = parseAccountType(option.parent.accountType);
9177
const passphrase = parsePassphrase(option.passphrase);
9278
await createKey(cckey, accountType, passphrase);
9379
}
9480

9581
async function deleteCommand(option: DeleteOption) {
9682
const cckey = await CCKey.create();
97-
const accountType = parseAccountType(option.accountType);
83+
const accountType = parseAccountType(option.parent.accountType);
9884
const address = parseAddress(option.address);
9985
await deleteKey(cckey, accountType, address);
10086
}
10187

10288
async function importCommand(path: string, option: ImportOption) {
10389
const cckey = await CCKey.create();
104-
const accountType = parseAccountType(option.accountType);
90+
const accountType = parseAccountType(option.parent.accountType);
10591
const passphrase = parsePassphrase(option.passphrase);
10692
const contents = fs.readFileSync(path, { encoding: "utf8" });
10793
await importKey(cckey, accountType, JSON.parse(contents), passphrase);

src/types.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@ export type AccountType = "platform" | "asset";
22
export type Action = "list" | "create" | "delete";
33

44
export interface ListOption {
5-
accountType: string;
5+
parent: {
6+
accountType: string;
7+
};
68
}
79

810
export interface CreateOption {
9-
accountType: string;
11+
parent: {
12+
accountType: string;
13+
};
1014
passphrase: string;
1115
}
1216

1317
export interface DeleteOption {
14-
accountType: string;
18+
parent: {
19+
accountType: string;
20+
};
1521
address: string;
1622
}
1723

1824
export interface ImportOption {
19-
accountType: string;
25+
parent: {
26+
accountType: string;
27+
};
2028
passphrase: string;
2129
}

0 commit comments

Comments
 (0)