Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/client/lib/Input.ts
1028 views
1
export function readCommandLineArgs(): any {
2
const input = {};
3
const argv = process.argv.slice(2);
4
5
for (const arg of argv) {
6
const [rawArg, ...values] = arg.split('=');
7
if (!rawArg.startsWith('--input')) return null;
8
let name = rawArg.replace('--input', '');
9
if (name.startsWith('.')) name = name.substr(1);
10
11
let value = values.join('=');
12
if (value.startsWith('"') && value.endsWith('"')) value = value.substr(1, value.length - 2);
13
14
let owner = input;
15
const path = name.split('.');
16
const param = path.pop();
17
for (const entry of path) {
18
if (!owner[entry]) {
19
if (!Number.isNaN(entry) && entry === '0') {
20
owner[entry] = [];
21
} else {
22
owner[entry] = {};
23
}
24
}
25
owner = owner[entry];
26
}
27
28
owner[param] = value;
29
}
30
return input;
31
}
32
33