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

Function parseArgs

scripts/static-server.mjs:92–238  ·  view source on GitHub ↗
(argv = process.argv.slice(2), env = process.env)

Source from the content-addressed store, hash-verified

90}
91
92export function parseArgs(argv = process.argv.slice(2), env = process.env) {
93 const config = {
94 port: 3001,
95 host: DEFAULT_BIND_HOST,
96 dir: "build",
97 routes: {},
98 rejectPrefixes: [],
99 noReferrerPrefixes: [],
100 sessionApiKey: null,
101 authRequired: false,
102 allowLanSessionKey: false,
103 runtimeServicesInfo: null,
104 lockToCloud: null,
105 basePath: "/",
106 vscodeBasePath: null,
107 // Also settable via the --disable-telemetry flag below.
108 disableTelemetry: isEnvFlagEnabled(env.AGENT_CANVAS_DISABLE_TELEMETRY),
109 };
110
111 for (let i = 0; i < argv.length; i++) {
112 const flag = argv[i];
113 switch (flag) {
114 case "-p":
115 case "--port":
116 config.port = Number.parseInt(argv[++i], 10);
117 break;
118 case "-H":
119 case "--host":
120 config.host = argv[++i];
121 break;
122 case "-d":
123 case "--dir":
124 config.dir = argv[++i];
125 break;
126 case "-r":
127 case "--route": {
128 const value = argv[++i];
129 const eq = value.indexOf("=");
130 if (eq < 0) {
131 throw new Error(`Invalid --route (expected /prefix=url): ${value}`);
132 }
133 const prefix = value.slice(0, eq);
134 const url = value.slice(eq + 1);
135 if (!prefix.startsWith("/")) {
136 throw new Error(`--route prefix must start with '/': ${prefix}`);
137 }
138 config.routes[prefix] = url;
139 break;
140 }
141 case "--session-api-key":
142 config.sessionApiKey = argv[++i] || null;
143 break;
144 case "--runtime-services-info":
145 config.runtimeServicesInfo = argv[++i] || null;
146 break;
147 case "--lock-to-cloud":
148 config.lockToCloud = argv[++i] || null;
149 break;

Callers 1

static-server.mjsFile · 0.70

Calls 4

isEnvFlagEnabledFunction · 0.85
errorMethod · 0.80
normalizeBasePathFunction · 0.70
showHelpFunction · 0.70

Tested by

no test coverage detected