Skip to content

Commit a96f3a2

Browse files
XXPermanentXXclaude
andcommitted
refactor: remove now-unused region threading in help printing
After dropping the API Reference line, printCommandHelp no longer reads region, so the --region/DASHSCOPE_REGION resolution done solely for help output is dead code. Endpoint selection via loadConfig is untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 489ba4f commit a96f3a2

2 files changed

Lines changed: 7 additions & 29 deletions

File tree

packages/cli/src/main.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import { registry } from "./registry.ts";
33
import {
44
GLOBAL_OPTIONS,
55
loadConfig,
6-
readConfigFile,
76
resolveCredential,
87
trackCommandExecution,
98
flushTelemetry,
10-
type Region,
119
} from "bailian-cli-core";
1210
import { ensureApiKey } from "./utils/ensure-key.ts";
1311
import { handleError } from "./error-handler.ts";
@@ -22,13 +20,7 @@ import {
2220
} from "./utils/command-help.ts";
2321

2422
registerCommandHelpPrinter((commandPath, out) => {
25-
const a = process.argv.slice(2);
26-
const ri = a.indexOf("--region");
27-
const region = ((ri >= 0 && a[ri + 1]) ||
28-
process.env.DASHSCOPE_REGION ||
29-
readConfigFile().region ||
30-
"cn") as Region;
31-
registry.printHelp(commandPath, out, region);
23+
registry.printHelp(commandPath, out);
3224
});
3325

3426
// 优雅处理 Ctrl+C
@@ -84,12 +76,7 @@ async function main() {
8476
const commandPath = scanCommandPath(argv, GLOBAL_OPTIONS);
8577

8678
if (argv.includes("--help") || argv.includes("-h")) {
87-
const ri = argv.indexOf("--region");
88-
const region = ((ri >= 0 && argv[ri + 1]) ||
89-
process.env.DASHSCOPE_REGION ||
90-
readConfigFile().region ||
91-
"cn") as Region;
92-
registry.printHelp(commandPath, process.stderr, region);
79+
registry.printHelp(commandPath, process.stderr);
9380
process.exit(0);
9481
}
9582

@@ -115,12 +102,7 @@ async function main() {
115102

116103
// 组路径(例如 `bl speech` 未接子命令):展示帮助后干净退出
117104
if (registry.isGroupPath(commandPath)) {
118-
const ri = argv.indexOf("--region");
119-
const region = ((ri >= 0 && argv[ri + 1]) ||
120-
process.env.DASHSCOPE_REGION ||
121-
readConfigFile().region ||
122-
"cn") as Region;
123-
registry.printHelp(commandPath, process.stderr, region);
105+
registry.printHelp(commandPath, process.stderr);
124106
process.exit(0);
125107
}
126108

packages/cli/src/registry.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Command } from "bailian-cli-core";
22
import { BailianError } from "bailian-cli-core";
33
import { ExitCode } from "bailian-cli-core";
4-
import { GLOBAL_OPTIONS, type Region } from "bailian-cli-core";
4+
import { GLOBAL_OPTIONS } from "bailian-cli-core";
55
import { commands } from "./commands/catalog.ts";
66

77
export type { Command, OptionDef } from "bailian-cli-core";
@@ -133,11 +133,7 @@ class CommandRegistry {
133133
out.isTTY ? `\x1b[38;2;59;130;246m${s}\x1b[0m` : s;
134134
private dim = (s: string, out: NodeJS.WriteStream) => (out.isTTY ? `\x1b[2m${s}\x1b[0m` : s);
135135

136-
printHelp(
137-
commandPath: string[],
138-
out: NodeJS.WriteStream = process.stdout,
139-
region: Region = "cn",
140-
): void {
136+
printHelp(commandPath: string[], out: NodeJS.WriteStream = process.stdout): void {
141137
if (commandPath.length === 0) {
142138
this.printRootHelp(out);
143139
return;
@@ -154,7 +150,7 @@ class CommandRegistry {
154150
}
155151

156152
if (node.command) {
157-
this.printCommandHelp(node.command, out, region);
153+
this.printCommandHelp(node.command, out);
158154
return;
159155
}
160156

@@ -233,7 +229,7 @@ ${b("Getting Help:")}
233229
`);
234230
}
235231

236-
private printCommandHelp(cmd: Command, out: NodeJS.WriteStream, region: Region = "cn"): void {
232+
private printCommandHelp(cmd: Command, out: NodeJS.WriteStream): void {
237233
const b = (s: string) => this.bold(s, out);
238234
const a = (s: string) => this.accent(s, out);
239235
const d = (s: string) => this.dim(s, out);

0 commit comments

Comments
 (0)