Skip to content

Commit f9a3ecb

Browse files
committed
feat: add region-aware apiDocs support to command help
Add DOCS_HOSTS constant mapping regions to their docs platform hosts (global → platform.minimax.io, cn → platform.minimaxi.com). Commands can now set apiDocs to a path (e.g. /docs/api-reference/music-generation) and the correct host is resolved from the user's region at display time.
1 parent 5436176 commit f9a3ecb

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Command {
1414
usage?: string;
1515
options?: OptionDef[];
1616
examples?: string[];
17+
apiDocs?: string;
1718
execute(config: Config, flags: GlobalFlags): Promise<void>;
1819
}
1920

@@ -23,6 +24,7 @@ export interface CommandSpec {
2324
usage?: string;
2425
options?: OptionDef[];
2526
examples?: string[];
27+
apiDocs?: string;
2628
run(config: Config, flags: GlobalFlags): Promise<void>;
2729
}
2830

@@ -33,6 +35,7 @@ export function defineCommand(spec: CommandSpec): Command {
3335
usage: spec.usage,
3436
options: spec.options,
3537
examples: spec.examples,
38+
apiDocs: spec.apiDocs,
3639
execute: spec.run,
3740
};
3841
}

src/config/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ export const REGIONS = {
33
cn: 'https://api.minimaxi.com',
44
} as const;
55

6+
export const DOCS_HOSTS = {
7+
global: 'https://platform.minimax.io',
8+
cn: 'https://platform.minimaxi.com',
9+
} as const;
10+
611
export type Region = keyof typeof REGIONS;
712

813
export interface ConfigFile {

src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { scanCommandPath, parseFlags } from './args';
22
import { registry } from './registry';
33
import { GLOBAL_OPTIONS } from './command';
44
import { handleError } from './errors/handler';
5-
import { loadConfig } from './config/loader';
5+
import { loadConfig, readConfigFile } from './config/loader';
66
import { detectRegion, saveDetectedRegion } from './config/detect-region';
7-
import { REGIONS } from './config/schema';
7+
import { REGIONS, type Region } from './config/schema';
88
import { checkForUpdate, getPendingUpdateNotification } from './update/checker';
99
import { loadCredentials } from './auth/credentials';
1010
import { ensureApiKey } from './auth/setup';
@@ -44,7 +44,9 @@ async function main() {
4444
const commandPath = scanCommandPath(argv, GLOBAL_OPTIONS);
4545

4646
if (argv.includes('--help') || argv.includes('-h')) {
47-
registry.printHelp(commandPath, process.stderr);
47+
const ri = argv.indexOf('--region');
48+
const region = ((ri >= 0 && argv[ri + 1]) || process.env.MINIMAX_REGION || readConfigFile().region || 'global') as Region;
49+
registry.printHelp(commandPath, process.stderr, region);
4850
process.exit(0);
4951
}
5052

src/registry.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Command } from './command';
22
import { CLIError } from './errors/base';
33
import { ExitCode } from './errors/codes';
4+
import { DOCS_HOSTS, type Region } from './config/schema';
45

56
import authLogin from './commands/auth/login';
67
import authStatus from './commands/auth/status';
@@ -119,7 +120,7 @@ class CommandRegistry {
119120
private accent = (s: string, out: NodeJS.WriteStream) => out.isTTY ? `\x1b[38;2;248;103;58m${s}\x1b[0m` : s;
120121
private dim = (s: string, out: NodeJS.WriteStream) => out.isTTY ? `\x1b[2m${s}\x1b[0m` : s;
121122

122-
printHelp(commandPath: string[], out: NodeJS.WriteStream = process.stdout): void {
123+
printHelp(commandPath: string[], out: NodeJS.WriteStream = process.stdout, region: Region = 'global'): void {
123124
if (commandPath.length === 0) {
124125
this.printRootHelp(out);
125126
return;
@@ -136,7 +137,7 @@ class CommandRegistry {
136137
}
137138

138139
if (node.command) {
139-
this.printCommandHelp(node.command, out);
140+
this.printCommandHelp(node.command, out, region);
140141
return;
141142
}
142143

@@ -217,7 +218,7 @@ ${b('Getting Help:')}
217218
`);
218219
}
219220

220-
private printCommandHelp(cmd: Command, out: NodeJS.WriteStream): void {
221+
private printCommandHelp(cmd: Command, out: NodeJS.WriteStream, region: Region = 'global'): void {
221222
const b = (s: string) => this.bold(s, out);
222223
const a = (s: string) => this.accent(s, out);
223224
const d = (s: string) => this.dim(s, out);
@@ -237,6 +238,9 @@ ${b('Getting Help:')}
237238
out.write(` ${d(ex)}\n`);
238239
}
239240
}
241+
if (cmd.apiDocs) {
242+
out.write(`\n${b('API Reference:')} ${d(DOCS_HOSTS[region] + cmd.apiDocs)}\n`);
243+
}
240244
out.write(`\n${d('Global flags (--api-key, --output, --quiet, etc.) are always available.')}\n`);
241245
out.write(`${d("Run")} mmx --help ${d('for the full list.')}\n`);
242246
}

0 commit comments

Comments
 (0)