MCPcopy Create free account
hub / github.com/bytebase/dbhub / parseCommandLineArgs

Function parseCommandLineArgs

src/config/env.ts:18–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17// Parse command line arguments
18export function parseCommandLineArgs() {
19 // Check if any args start with '--' (the way tsx passes them)
20 const args = process.argv.slice(2);
21 const parsedManually: Record<string, string> = {};
22
23 for (let i = 0; i < args.length; i++) {
24 const arg = args[i];
25 if (arg.startsWith("--")) {
26 const parts = arg.substring(2).split("=");
27 const key = parts[0];
28
29 // Fail immediately on deprecated flags
30 if (key === "readonly") {
31 console.error("\nERROR: --readonly flag is no longer supported.");
32 console.error("Use dbhub.toml with [[tools]] configuration instead:\n");
33 console.error(" [[sources]]");
34 console.error(" id = \"default\"");
35 console.error(" dsn = \"...\"\n");
36 console.error(" [[tools]]");
37 console.error(" name = \"execute_sql\"");
38 console.error(" source = \"default\"");
39 console.error(" readonly = true\n");
40 console.error("See https://dbhub.ai/tools/execute-sql#read-only-mode for details.\n");
41 process.exit(1);
42 }
43
44 if (key === "max-rows") {
45 console.error("\nERROR: --max-rows flag is no longer supported.");
46 console.error("Use dbhub.toml with [[tools]] configuration instead:\n");
47 console.error(" [[sources]]");
48 console.error(" id = \"default\"");
49 console.error(" dsn = \"...\"\n");
50 console.error(" [[tools]]");
51 console.error(" name = \"execute_sql\"");
52 console.error(" source = \"default\"");
53 console.error(" max_rows = 1000\n");
54 console.error("See https://dbhub.ai/tools/execute-sql#row-limiting for details.\n");
55 process.exit(1);
56 }
57
58 const value = parts.length > 1 ? parts.slice(1).join("=") : undefined;
59 if (value) {
60 // Handle --key=value format
61 parsedManually[key] = value;
62 } else if (i + 1 < args.length && !args[i + 1].startsWith("--")) {
63 // Handle --key value format
64 parsedManually[key] = args[i + 1];
65 i++; // Skip the next argument as it's the value
66 } else {
67 // Handle --key format (boolean flag)
68 parsedManually[key] = "true";
69 }
70 }
71 }
72
73 // Just use the manually parsed args - removed parseArgs dependency for Node.js <18.3.0 compatibility
74 return parsedManually;
75}

Callers 9

resolveTomlConfigPathFunction · 0.85
isDemoModeFunction · 0.85
resolveDSNFunction · 0.85
resolveTransportFunction · 0.85
resolvePortFunction · 0.85
resolveHostFunction · 0.85
resolveAllowedHostsFunction · 0.85
resolveIdFunction · 0.85
resolveSSHConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected