-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
58 lines (51 loc) · 1.52 KB
/
config.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
import { parse } from "@std/toml";
import { join } from "@std/path";
let config: Record<string, unknown> = {};
async function loadConfig() {
const configPaths = [
"./linear.toml",
"./.linear.toml",
];
try {
const gitProcess = await new Deno.Command("git", {
args: ["rev-parse", "--show-toplevel"],
}).output();
const gitRoot = new TextDecoder().decode(gitProcess.stdout).trim();
configPaths.push(join(gitRoot, "linear.toml"));
configPaths.push(join(gitRoot, ".linear.toml"));
configPaths.push(join(gitRoot, ".config", "linear.toml"));
} catch {
// Not in a git repository; ignore additional paths.
}
for (const path of configPaths) {
try {
await Deno.stat(path);
const file = await Deno.readTextFile(path);
config = parse(file) as Record<string, unknown>;
break;
} catch {
// File not found; continue.
}
}
}
await loadConfig();
export type OptionValueMapping = {
team_id: string;
api_key: string;
workspace: string;
issue_sort: "manual" | "priority";
};
export type OptionName = keyof OptionValueMapping;
export function getOption<T extends OptionName>(
optionName: T,
cliValue?: string,
): OptionValueMapping[T] | undefined {
if (cliValue !== undefined) return cliValue as OptionValueMapping[T];
const fromConfig = config[optionName];
if (typeof fromConfig === "string") {
return fromConfig as OptionValueMapping[T];
}
return Deno.env.get("LINEAR_" + optionName.toUpperCase()) as
| OptionValueMapping[T]
| undefined;
}