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

Function parseArgs

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

Source from the content-addressed store, hash-verified

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