Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/core/env.ts
3557 views
1
/*
2
* env.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { isWindows } from "../deno_ral/platform.ts";
8
9
export function getenv(name: string, defaultValue?: string) {
10
const value = Deno.env.get(name);
11
if (value === undefined) {
12
if (defaultValue === undefined) {
13
throw new Error(`Required environment variable ${name} not specified.`);
14
} else {
15
return defaultValue;
16
}
17
} else {
18
return value;
19
}
20
}
21
22
export function withPath(
23
paths: { append?: string[]; prepend?: string[] },
24
): string {
25
const delimiter = isWindows ? ";" : ":";
26
27
const currentPath = Deno.env.get("PATH") || "";
28
if (paths.append !== undefined && paths.prepend !== undefined) {
29
// Nothing to append or prepend
30
return currentPath;
31
} else if (paths.append?.length === 0 && paths.prepend?.length === 0) {
32
// Nothing to append or prepend
33
return currentPath;
34
} else {
35
// Make a new path
36
const modifiedPaths = [currentPath];
37
if (paths.append) {
38
modifiedPaths.unshift(...paths.append);
39
}
40
41
if (paths.prepend) {
42
modifiedPaths.push(...paths.prepend);
43
}
44
return modifiedPaths.join(delimiter);
45
}
46
}
47
48