@tkpdx01/ccc 1.2.3 → 1.2.5
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/package.json +1 -1
- package/src/commands/list.js +15 -26
package/package.json
CHANGED
package/src/commands/list.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
3
|
import Table from 'cli-table3';
|
|
3
|
-
import { getProfiles, getDefaultProfile, getProfilePath
|
|
4
|
+
import { getProfiles, getDefaultProfile, getProfilePath } from '../profiles.js';
|
|
4
5
|
|
|
5
6
|
export function listCommand(program) {
|
|
6
7
|
program
|
|
@@ -18,7 +19,7 @@ export function listCommand(program) {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
const table = new Table({
|
|
21
|
-
head: [chalk.cyan('#'), chalk.cyan('Profile'), chalk.cyan('
|
|
22
|
+
head: [chalk.cyan('#'), chalk.cyan('Profile'), chalk.cyan('ANTHROPIC_BASE_URL')],
|
|
22
23
|
style: { head: [], border: [] },
|
|
23
24
|
chars: {
|
|
24
25
|
'top': '─', 'top-mid': '┬', 'top-left': '┌', 'top-right': '┐',
|
|
@@ -30,35 +31,23 @@ export function listCommand(program) {
|
|
|
30
31
|
|
|
31
32
|
profiles.forEach((p, index) => {
|
|
32
33
|
const isDefault = p === defaultProfile;
|
|
33
|
-
const
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
apiUrl = settings.apiUrl;
|
|
43
|
-
} else if (settings.env) {
|
|
44
|
-
if (Array.isArray(settings.env)) {
|
|
45
|
-
// 数组格式,用正则提取
|
|
46
|
-
const envLine = settings.env.find(e => /^ANTHROPIC_BASE_URL=/.test(e));
|
|
47
|
-
if (envLine) {
|
|
48
|
-
apiUrl = envLine.replace(/^ANTHROPIC_BASE_URL=/, '');
|
|
49
|
-
}
|
|
50
|
-
} else if (typeof settings.env === 'object') {
|
|
51
|
-
// 对象格式
|
|
52
|
-
apiUrl = settings.env.ANTHROPIC_BASE_URL || chalk.gray('(未设置)');
|
|
53
|
-
}
|
|
34
|
+
const profilePath = getProfilePath(p);
|
|
35
|
+
let baseUrl = chalk.gray('(未设置)');
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const content = fs.readFileSync(profilePath, 'utf-8');
|
|
39
|
+
// 用正则从 JSON 文件内容中提取 ANTHROPIC_BASE_URL
|
|
40
|
+
const match = content.match(/"ANTHROPIC_BASE_URL"\s*:\s*"([^"]+)"/);
|
|
41
|
+
if (match && match[1]) {
|
|
42
|
+
baseUrl = match[1];
|
|
54
43
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
44
|
+
} catch {
|
|
45
|
+
baseUrl = chalk.red('(读取失败)');
|
|
57
46
|
}
|
|
58
47
|
|
|
59
48
|
const num = isDefault ? chalk.green(`${index + 1}`) : chalk.gray(`${index + 1}`);
|
|
60
49
|
const name = isDefault ? chalk.green(`${p} *`) : p;
|
|
61
|
-
table.push([num, name,
|
|
50
|
+
table.push([num, name, baseUrl]);
|
|
62
51
|
});
|
|
63
52
|
|
|
64
53
|
console.log();
|