This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·65 lines (51 loc) · 1.56 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const library = require('./package.json');
const env = require('.');
const args = process.argv.splice(2);
const opts = args.reduce((p, c, i, a) => {
if (c.startsWith('-')) {
let value = a[i + 1];
if (!value || value.startsWith('-')) {
value = true;
}
const key = c.replace(/^-+/, '');
p[key] = value;
}
return p;
}, {});
function getHelpInfo() {
return `
Usage: ${library.name} [flags]
Options:
-v, --version output version number (current: ${library.version})
-c, --context <context> use specific context from TOML file
accepts: production, deploy-preview, branch-deploy
and development, which is a custom context
(default: $CONTEXT || development)
-f, --file <path> path to a specific TOML file to parse configuration
from (default: netlify.toml)
Examples:
netlify-env
netlify-env --context deploy-preview
netlify-env --context branch-deploy --file config.toml
Visit ${library.repository} for more information
`;
}
if (opts.version || opts.v) {
console.info(library.version);
process.exit(0);
}
if (opts.help || opts.h) {
console.info(getHelpInfo());
process.exit(0);
}
async function main() {
const options = {
context: opts.c || opts.context,
file: opts.f || opts.file
};
const v = await env(process.cwd(), options);
const output = Object.entries(v).map(kv => kv.join('=')).join('\n');
process.stdout.write(output + '\n');
}
main().catch(console.log);