This repository has been archived by the owner on Mar 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.ts
69 lines (55 loc) · 1.65 KB
/
get.ts
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
66
67
68
69
import { flags } from "@oclif/command";
import chalk from 'chalk';
import Table from 'cli-table';
import AppBaseCommand from "../../base-app-command";
export default class Get extends AppBaseCommand {
static description = "Get environment variables for an app";
static strict = false;
static aliases = ['get'];
static flags = {
...AppBaseCommand.flags,
help: flags.help({
char: "h",
description: "show help for the env command",
})
};
static args = [
{
name: "NAME-1 ... NAME-N",
description: "the environment variable name(s). e.g. FOO (note: name will always be UPPERCASED)",
required: true,
}
]
async run(): Promise<void> {
if (!(this.client && this.platformApp)) {
this.error("Initialization failed - invalid state");
return;
}
const names = this.argv.map(a => a.toUpperCase());
try {
const configurationKeys = await this.client.configuration.list(this.platformApp.id);
if (!(configurationKeys && configurationKeys.length > 0)) {
this.log(`${this.platformApp.name} has no environment variables set`)
return;
}
const table = new Table({
head: [
chalk.green('Name'),
chalk.green("Value")
]
});
configurationKeys.filter(key => names.includes(key.name)).forEach(key => {
table.push([key.name, key.value]);
});
if (table.length >= 1) {
this.log(table.toString());
} else {
this.warn(`none of ${names.join(",")} exist`);
}
} catch (error) {
return this.error("Error retrieving environment variables", {
exit: 1,
});
}
}
}