yuangs 1.3.33 → 1.3.34
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/cli.js +60 -0
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -173,8 +173,68 @@ async function handleAICommand() {
|
|
|
173
173
|
if (command) {
|
|
174
174
|
console.log(chalk.gray('生成命令:'));
|
|
175
175
|
console.log(chalk.bold.green(`> ${command}`));
|
|
176
|
+
|
|
177
|
+
// 1. Try to copy to clipboard
|
|
178
|
+
let copied = false;
|
|
179
|
+
try {
|
|
180
|
+
const { spawn } = require('child_process');
|
|
181
|
+
let copyCmd, copyArgs = [];
|
|
182
|
+
if (process.platform === 'darwin') {
|
|
183
|
+
copyCmd = 'pbcopy';
|
|
184
|
+
} else if (process.platform === 'win32') {
|
|
185
|
+
copyCmd = 'clip';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (copyCmd) {
|
|
189
|
+
const proc = spawn(copyCmd, copyArgs);
|
|
190
|
+
proc.stdin.write(command);
|
|
191
|
+
proc.stdin.end();
|
|
192
|
+
copied = true;
|
|
193
|
+
console.log(chalk.gray('(已复制到剪贴板)'));
|
|
194
|
+
}
|
|
195
|
+
} catch (e) {
|
|
196
|
+
// Ignore copy errors
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 2. Pre-fill and ask to execute
|
|
200
|
+
const readline = require('readline');
|
|
201
|
+
const rl = readline.createInterface({
|
|
202
|
+
input: process.stdin,
|
|
203
|
+
output: process.stdout
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
console.log(chalk.gray('👇 您可以直接回车执行,或修改后回车:'));
|
|
207
|
+
|
|
208
|
+
// This puts the command into the input line, effectively "pre-filling" it
|
|
209
|
+
rl.write(command);
|
|
210
|
+
|
|
211
|
+
rl.on('line', (input) => {
|
|
212
|
+
rl.close();
|
|
213
|
+
const finalCommand = input.trim();
|
|
214
|
+
|
|
215
|
+
if (!finalCommand) {
|
|
216
|
+
process.exit(0);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const { spawn } = require('child_process');
|
|
220
|
+
console.log(chalk.gray('正在执行...'));
|
|
221
|
+
// Use shell: true to support pipes, redirects, etc.
|
|
222
|
+
const child = spawn(finalCommand, [], { shell: true, stdio: 'inherit' });
|
|
223
|
+
|
|
224
|
+
child.on('close', (code) => {
|
|
225
|
+
if (code !== 0) {
|
|
226
|
+
console.log(chalk.red(`\n命令执行失败 (退出码: ${code})`));
|
|
227
|
+
}
|
|
228
|
+
process.exit(code);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Return to avoid continuing to other logic, let callback handle exit
|
|
233
|
+
return;
|
|
234
|
+
|
|
176
235
|
} else {
|
|
177
236
|
console.log(chalk.yellow('未能生成有效的命令。'));
|
|
237
|
+
process.exit(1);
|
|
178
238
|
}
|
|
179
239
|
return;
|
|
180
240
|
}
|