travel-agent-cli 0.4.3 → 0.4.4
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/interactive.jsx +22 -4
- package/package.json +1 -1
package/interactive.jsx
CHANGED
|
@@ -29,25 +29,43 @@ const commands = [
|
|
|
29
29
|
{ label: 'help - 帮助信息', value: 'help' },
|
|
30
30
|
];
|
|
31
31
|
|
|
32
|
+
// 查找 Python 命令
|
|
33
|
+
function findPython() {
|
|
34
|
+
const { execSync } = require('child_process');
|
|
35
|
+
const candidates = ['python3', 'python'];
|
|
36
|
+
|
|
37
|
+
for (const cmd of candidates) {
|
|
38
|
+
try {
|
|
39
|
+
execSync(`${cmd} --version`, { stdio: 'ignore' });
|
|
40
|
+
return cmd;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return 'python3'; // 默认使用 python3
|
|
47
|
+
}
|
|
48
|
+
|
|
32
49
|
// 执行 Python 命令
|
|
33
50
|
const runPythonCommand = (cmd, args) => {
|
|
34
51
|
return new Promise((resolve, reject) => {
|
|
35
52
|
let output = '';
|
|
36
53
|
let error = '';
|
|
37
54
|
|
|
38
|
-
const pythonCmd =
|
|
55
|
+
const pythonCmd = findPython();
|
|
56
|
+
const proc = spawn(pythonCmd, [mainPy, cmd, ...args], {
|
|
39
57
|
cwd: pythonDir,
|
|
40
58
|
});
|
|
41
59
|
|
|
42
|
-
|
|
60
|
+
proc.stdout.on('data', (data) => {
|
|
43
61
|
output += data.toString();
|
|
44
62
|
});
|
|
45
63
|
|
|
46
|
-
|
|
64
|
+
proc.stderr.on('data', (data) => {
|
|
47
65
|
error += data.toString();
|
|
48
66
|
});
|
|
49
67
|
|
|
50
|
-
|
|
68
|
+
proc.on('close', (code) => {
|
|
51
69
|
if (code === 0) {
|
|
52
70
|
resolve(output.trim());
|
|
53
71
|
} else {
|