aihezu 2.1.0 → 2.2.0
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/bin/aihezu.js +40 -22
- package/package.json +1 -1
package/bin/aihezu.js
CHANGED
|
@@ -38,77 +38,95 @@ async function askQuestion(rl, question) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
async function main() {
|
|
41
|
-
// Removed global rl creation
|
|
42
|
-
|
|
43
41
|
try {
|
|
44
|
-
if (args.length === 0 || args[0] === 'help') {
|
|
42
|
+
if (args.length === 0 || args[0] === 'help') {
|
|
45
43
|
showHelp();
|
|
46
44
|
return;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
const commandName = args[0];
|
|
50
|
-
let serviceName = args[1];
|
|
51
|
-
|
|
52
48
|
if (!commands[commandName]) {
|
|
53
|
-
console.error(`❌
|
|
49
|
+
console.error(`❌ 未知命令: ${commandName}`);
|
|
54
50
|
showHelp();
|
|
55
51
|
process.exit(1);
|
|
56
52
|
}
|
|
57
53
|
|
|
54
|
+
let serviceName = '';
|
|
55
|
+
let commandArgs = [];
|
|
56
|
+
|
|
57
|
+
// Check if the second argument is a service name or an option/flag
|
|
58
|
+
if (args.length > 1 && !args[1].startsWith('-')) {
|
|
59
|
+
serviceName = args[1].toLowerCase();
|
|
60
|
+
commandArgs = args.slice(2);
|
|
61
|
+
} else {
|
|
62
|
+
// No service name provided, or an option was provided instead.
|
|
63
|
+
// The command arguments will be all arguments after the command itself.
|
|
64
|
+
commandArgs = args.slice(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If service name is not provided, and command is 'install', enter interactive mode.
|
|
58
68
|
if (!serviceName) {
|
|
59
69
|
if (commandName === 'install') {
|
|
60
|
-
// Init rl ONLY here for selection
|
|
61
70
|
const rl = readline.createInterface({
|
|
62
71
|
input: process.stdin,
|
|
63
72
|
output: process.stdout
|
|
64
73
|
});
|
|
65
74
|
|
|
66
75
|
try {
|
|
67
|
-
// Interactive service selection for 'install' command
|
|
68
76
|
console.log('\n请选择要安装的服务:');
|
|
69
77
|
const serviceKeys = Object.keys(services);
|
|
78
|
+
const claudeIndex = serviceKeys.indexOf('claude');
|
|
79
|
+
|
|
70
80
|
serviceKeys.forEach((key, index) => {
|
|
71
|
-
|
|
81
|
+
const isDefault = (key === 'claude');
|
|
82
|
+
console.log(` [${index + 1}] ${services[key].displayName}${isDefault ? ' (默认)' : ''}`);
|
|
72
83
|
});
|
|
73
84
|
|
|
74
|
-
let chosenIndex;
|
|
85
|
+
let chosenIndex = claudeIndex !== -1 ? claudeIndex : 0; // Default to Claude
|
|
75
86
|
let validChoice = false;
|
|
87
|
+
|
|
76
88
|
while (!validChoice) {
|
|
77
|
-
const answer = await askQuestion(rl, '
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
serviceName = serviceKeys[chosenIndex];
|
|
81
|
-
validChoice = true;
|
|
89
|
+
const answer = await askQuestion(rl, '请输入选项编号 (直接回车使用默认值): ');
|
|
90
|
+
if (answer === '') {
|
|
91
|
+
validChoice = true; // Use the default index
|
|
82
92
|
} else {
|
|
83
|
-
|
|
93
|
+
const selectedIdx = parseInt(answer, 10) - 1;
|
|
94
|
+
if (selectedIdx >= 0 && selectedIdx < serviceKeys.length) {
|
|
95
|
+
chosenIndex = selectedIdx;
|
|
96
|
+
validChoice = true;
|
|
97
|
+
} else {
|
|
98
|
+
console.log('无效的选择,请输入列表中的数字。');
|
|
99
|
+
}
|
|
84
100
|
}
|
|
85
101
|
}
|
|
102
|
+
serviceName = serviceKeys[chosenIndex];
|
|
86
103
|
console.log(`✅ 已选择: ${services[serviceName].displayName}`);
|
|
104
|
+
|
|
87
105
|
} finally {
|
|
88
|
-
// Close rl immediately after selection and BEFORE calling the command
|
|
89
106
|
rl.close();
|
|
90
107
|
}
|
|
91
108
|
} else {
|
|
92
|
-
// For 'clear'
|
|
109
|
+
// For other commands like 'clear', service name is mandatory.
|
|
93
110
|
console.error(`❌ 请为 '${commandName}' 命令指定一个服务名称。`);
|
|
94
111
|
showHelp();
|
|
95
112
|
process.exit(1);
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
115
|
|
|
99
|
-
const service = services[serviceName
|
|
116
|
+
const service = services[serviceName];
|
|
100
117
|
if (!service) {
|
|
101
118
|
console.error(`❌ 未知服务: ${serviceName}`);
|
|
102
119
|
console.log('可用服务: ' + Object.keys(services).map(key => services[key].displayName).join(', '));
|
|
103
120
|
process.exit(1);
|
|
104
121
|
}
|
|
105
122
|
|
|
106
|
-
// Execute
|
|
107
|
-
await commands[commandName](service,
|
|
123
|
+
// Execute the command with the correct service and arguments
|
|
124
|
+
await commands[commandName](service, commandArgs);
|
|
125
|
+
|
|
108
126
|
} catch (error) {
|
|
109
127
|
console.error('❌ 发生错误:', error);
|
|
110
128
|
process.exit(1);
|
|
111
129
|
}
|
|
112
130
|
}
|
|
113
131
|
|
|
114
|
-
main();
|
|
132
|
+
main();
|