MCPcopy
hub / github.com/MiniMax-AI/cli / main

Function main

src/main.ts:36–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34];
35
36async function main() {
37 const argv = process.argv.slice(2);
38
39 if (argv.includes('--version') || argv.includes('-v')) {
40 console.log(`mmx ${CLI_VERSION}`);
41 process.exit(0);
42 }
43
44 const commandPath = scanCommandPath(argv, GLOBAL_OPTIONS);
45
46 // Proxy: env vars take precedence over config file
47 const rawConfig = readConfigFile();
48 const proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy
49 || process.env.HTTP_PROXY || process.env.http_proxy
50 || process.env.ALL_PROXY || process.env.all_proxy
51 || rawConfig.proxy;
52 if (proxyUrl) {
53 setGlobalDispatcher(new ProxyAgent(proxyUrl));
54 }
55
56 if (argv.includes('--help') || argv.includes('-h')) {
57 const ri = argv.indexOf('--region');
58 const region = ((ri >= 0 && argv[ri + 1]) || process.env.MINIMAX_REGION || rawConfig.region || 'global') as Region;
59 registry.printHelp(commandPath, process.stderr, region);
60 process.exit(0);
61 }
62
63 // No command: help + quota (if logged in) or login guide
64 if (commandPath.length === 0) {
65 registry.printHelp([], process.stderr);
66
67 const { command: quotaCmd } = registry.resolve(['quota', 'show']);
68 const flags = parseFlags(argv, [...GLOBAL_OPTIONS, ...(quotaCmd.options ?? [])]);
69 const config = loadConfig(flags);
70
71 const hasKey = !!(config.apiKey || config.fileApiKey);
72 const hasOAuth = !!(await loadCredentials());
73
74 if (hasKey || hasOAuth) {
75 await quotaCmd.execute(config, flags);
76 } else {
77 process.stderr.write(' Not logged in.\n');
78 process.stderr.write(' mmx auth login Choose MiniMax OAuth (Global/China) or paste an API key\n');
79 process.stderr.write(' mmx auth login --api-key Save an API key directly\n\n');
80 }
81 process.exit(0);
82 }
83
84 const { command, extra } = registry.resolve(commandPath);
85 const flags = parseFlags(argv, [...GLOBAL_OPTIONS, ...(command.options ?? [])]);
86
87 if (extra.length > 0) (flags as Record<string, unknown>)._positional = extra;
88
89 const config = loadConfig(flags);
90
91 const needsAuthSetup = !NO_AUTH_SETUP.some(
92 (cmd) => cmd.every((c, i) => commandPath[i] === c),
93 );

Callers 1

main.tsFile · 0.85

Calls 13

scanCommandPathFunction · 0.90
readConfigFileFunction · 0.90
parseFlagsFunction · 0.90
loadConfigFunction · 0.90
loadCredentialsFunction · 0.90
ensureAuthFunction · 0.90
detectRegionFunction · 0.90
saveDetectedRegionFunction · 0.90
checkForUpdateFunction · 0.90
printHelpMethod · 0.80
resolveMethod · 0.80

Tested by

no test coverage detected