soluser 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -4
- package/bin/index.js +16 -7
- package/package.json +1 -1
- package/src/commands/remove.js +44 -0
package/README.md
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
# soluser
|
|
2
2
|
# 新建账号
|
|
3
|
-
|
|
4
|
-
soluser new --
|
|
3
|
+
```shell
|
|
4
|
+
$ soluser new alice --word-length 12
|
|
5
|
+
$ soluser new bob --word-length 24 --no-bip39-passphrase
|
|
6
|
+
$ soluser new charlie
|
|
7
|
+
```
|
|
5
8
|
|
|
6
9
|
# 切换账号
|
|
7
|
-
|
|
10
|
+
```shell
|
|
11
|
+
$ soluser switch --address alice
|
|
12
|
+
```
|
|
8
13
|
|
|
9
14
|
# 列出账号
|
|
10
|
-
|
|
15
|
+
```shell
|
|
16
|
+
$ soluser list
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
# 删除账号
|
|
20
|
+
```shell
|
|
21
|
+
$ soluser remove alice
|
|
22
|
+
```
|
|
11
23
|
|
|
12
24
|
# 本地安装
|
|
13
25
|
```shell
|
package/bin/index.js
CHANGED
|
@@ -4,21 +4,21 @@ const { program } = require('commander');
|
|
|
4
4
|
const newAccount = require('../src/commands/new');
|
|
5
5
|
const switchAccount = require('../src/commands/switch');
|
|
6
6
|
const listAccounts = require('../src/commands/list');
|
|
7
|
+
const removeAccount = require('../src/commands/remove');
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
// 定义新建账号命令
|
|
11
|
+
// 定义新建账号命令(修改后)
|
|
9
12
|
program
|
|
10
13
|
.command('new')
|
|
11
14
|
.description('Create a new Solana account')
|
|
12
|
-
.
|
|
15
|
+
.argument('<alias>', 'Alias for the new account (must start with a letter, contain letters, digits, hyphens, or underscores)') // 新增位置参数
|
|
13
16
|
.option('--word-length <number>', 'Number of words in seed phrase (12,15,18,21,24)', 12)
|
|
14
17
|
.option('--no-bip39-passphrase', 'Do not prompt for BIP39 passphrase')
|
|
15
|
-
.action((options) => {
|
|
16
|
-
if (!options.alias) {
|
|
17
|
-
throw new Error('Alias is required (use --alias <name>)');
|
|
18
|
-
}
|
|
18
|
+
.action((alias, options) => { // 第一个参数为位置参数 alias,第二个为选项
|
|
19
19
|
newAccount(
|
|
20
|
-
|
|
21
|
-
parseInt(options.wordLength, 10),
|
|
20
|
+
alias, // 直接使用位置参数的 alias
|
|
21
|
+
parseInt(options.wordLength, 10), //10进制解析
|
|
22
22
|
options.noBip39Passphrase
|
|
23
23
|
);
|
|
24
24
|
});
|
|
@@ -41,6 +41,15 @@ program
|
|
|
41
41
|
.description('List all Solana accounts')
|
|
42
42
|
.action(listAccounts);
|
|
43
43
|
|
|
44
|
+
// 定义删除账号命令
|
|
45
|
+
program
|
|
46
|
+
.command('remove <alias>') // <alias> 为必填参数
|
|
47
|
+
.description('Delete a Solana account (permanently removes the key file)')
|
|
48
|
+
.action((alias) => {
|
|
49
|
+
removeAccount(alias);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
44
53
|
// 解析命令行参数
|
|
45
54
|
program.parse(process.argv);
|
|
46
55
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { validateAlias, getKeyFilePath } = require('../utils/path');
|
|
3
|
+
const { getActiveKeyPath } = require('../utils/solana');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
function removeAccount(alias) {
|
|
7
|
+
// 1. 验证别名格式
|
|
8
|
+
validateAlias(alias);
|
|
9
|
+
|
|
10
|
+
// 2. 检查密钥文件是否存在
|
|
11
|
+
const keyPath = getKeyFilePath(alias);
|
|
12
|
+
if (!fs.existsSync(keyPath)) {
|
|
13
|
+
throw new Error(`Account "${alias}" not found. Use "soluser list" to check existing accounts.`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 3. 检查是否为当前活跃账号
|
|
17
|
+
const activeKeyPath = getActiveKeyPath();
|
|
18
|
+
const isActive = activeKeyPath === keyPath;
|
|
19
|
+
if (isActive) {
|
|
20
|
+
console.warn(`⚠️ Warning: "${alias}" is currently the active account. Deleting it will break current Solana config.`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 4. 确认删除(简单交互提示)
|
|
24
|
+
const readline = require('readline').createInterface({
|
|
25
|
+
input: process.stdin,
|
|
26
|
+
output: process.stdout
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
readline.question(`Are you sure you want to delete "${alias}"? This will permanently remove the key file (y/N): `, (answer) => {
|
|
30
|
+
readline.close();
|
|
31
|
+
if (answer.trim().toLowerCase() === 'y') {
|
|
32
|
+
// 执行删除
|
|
33
|
+
fs.unlinkSync(keyPath);
|
|
34
|
+
console.log(`✅ Successfully deleted account: ${alias}`);
|
|
35
|
+
if (isActive) {
|
|
36
|
+
console.log('ℹ️ Tip: Use "soluser switch --address <alias>" to set a new active account.');
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
console.log('❌ Deletion cancelled.');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = removeAccount;
|