MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / parseArgs

Function parseArgs

scripts/static-server.mjs:78–171  ·  view source on GitHub ↗
(argv = process.argv.slice(2))

Source from the content-addressed store, hash-verified

76// ─────────────────────────────────────────────────────────────────────────────
77
78export function parseArgs(argv = process.argv.slice(2)) {
79 const config = {
80 port: 3001,
81 host: "::",
82 dir: "build",
83 routes: {},
84 rejectPrefixes: [],
85 sessionApiKey: null,
86 authRequired: false,
87 runtimeServicesInfo: null,
88 lockToCloud: null,
89 basePath: "/",
90 };
91
92 for (let i = 0; i < argv.length; i++) {
93 const flag = argv[i];
94 switch (flag) {
95 case "-p":
96 case "--port":
97 config.port = Number.parseInt(argv[++i], 10);
98 break;
99 case "-H":
100 case "--host":
101 config.host = argv[++i];
102 break;
103 case "-d":
104 case "--dir":
105 config.dir = argv[++i];
106 break;
107 case "-r":
108 case "--route": {
109 const value = argv[++i];
110 const eq = value.indexOf("=");
111 if (eq < 0) {
112 throw new Error(`Invalid --route (expected /prefix=url): ${value}`);
113 }
114 const prefix = value.slice(0, eq);
115 const url = value.slice(eq + 1);
116 if (!prefix.startsWith("/")) {
117 throw new Error(`--route prefix must start with '/': ${prefix}`);
118 }
119 config.routes[prefix] = url;
120 break;
121 }
122 case "--session-api-key":
123 config.sessionApiKey = argv[++i] || null;
124 break;
125 case "--runtime-services-info":
126 config.runtimeServicesInfo = argv[++i] || null;
127 break;
128 case "--lock-to-cloud":
129 config.lockToCloud = argv[++i] || null;
130 break;
131 case "--base-path":
132 config.basePath = normalizeBasePath(argv[++i]);
133 break;
134
135 case "--auth-required":

Callers 1

static-server.mjsFile · 0.70

Calls 3

errorMethod · 0.80
normalizeBasePathFunction · 0.70
showHelpFunction · 0.70

Tested by

no test coverage detected