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
/
list.ts
65 lines (55 loc) · 1.66 KB
/
list.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
import { flags } from "@oclif/command";
import chalk from 'chalk';
import Table from 'cli-table';
import AppBaseCommand from "../../base-app-command";
export default class List extends AppBaseCommand {
static description = "List environment variables for an app";
static flags = {
...AppBaseCommand.flags,
help: flags.help({
char: "h",
description: "show help for the env command",
}),
format: flags.string({
char: "f",
description: "specify output format",
default: "table",
options: ["table", "dotenv"],
parse: (input) => input.toLowerCase(),
})
};
async run(): Promise<void> {
if (!(this.client && this.platformApp)) {
this.error("Initialization failed - invalid state");
return;
}
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 { flags } = this.parse(List);
if (flags.format === "table") {
const table = new Table({
head: [
chalk.green('Name'),
chalk.green("Value")
]
});
configurationKeys.forEach(key => {
table.push([key.name, key.value]);
});
this.log(table.toString());
} else if (flags.format === "dotenv") {
configurationKeys.forEach(key => {
this.log(`${key.name}=${key.value}`);
});
}
} catch (error) {
return this.error("Error retrieving environment variables", {
exit: 1,
});
}
}
}