-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcoffee.ts
36 lines (29 loc) · 1.86 KB
/
coffee.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
import coffee from "https://deno.land/x/coffee/mod.ts";
// if coffee.load() is not called, coffee automatically loads the configs from the './config' folder
let myDbName: string = coffee.get("database.user").string(); // my-db-name , loaded from default.json
coffee.has("database.host"); // false
coffee.set("database.host", "localhost"); // set new config
coffee.has("database.host"); // true
/* if default configs and custom-environment-variables have conflicts,
* and if target custom-environment-variable is available,
* default configs will be overwritten by target custom-environment-variable.
*/
let dbUser: string = coffee.get("database.user").string(); // DB_USER environment variable
let dbPassword: number = coffee.get("database.password").number(); // DB_PASSWORD environment variable
/* coffee can be reloaded config directory everywhere in the process,
* all new configs will be replaced.
*/
coffee.load({
configDir: "./custom",
customEnvVarFileName: "cev",
env: "production", // by default coffee read environment from `DENO_ENV` environment variable,
// this option is to force coffee to read from this env and ignore `DENO_ENV`.
});
let newDbName: string = coffee.get("database.name").string(); // my-new-db-name, loaded from default.yml config file
let newDbPassword: number = coffee.get("database.password").number(); // NEW_DB_PASSWORD, environment variable, loaded from cev.yml
let dbLimitation: number = coffee.get("database.limitaion").number(); // 10, loaded from production.json
/* coffee configurations can be forced and overwrited in command line arguments,
* as an example we can run : deno run --allow-read --allow-env coffee.ts --config.username=something
* note that for get config in coffee configurations we shoud prefix flags by "config".
*/
let username: number = coffee.get("username").number(); // something, readed from command line arguments