-
Notifications
You must be signed in to change notification settings - Fork 53
/
env.du
31 lines (25 loc) · 892 Bytes
/
env.du
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
import Env;
def readFile(path='.env') {
const SPLIT_DELIMITER = '=';
const COMMENT = '#';
with(path, 'r') {
var line;
var lineCount = 0;
// When you reach the end of the file, nil is returned
while((line = file.readLine()) != nil) {
lineCount = lineCount + 1;
if (not line or line.startsWith(COMMENT))
continue;
if (not line.contains('='))
return Error('Malformed entry on line {}'.format(lineCount));
const [variable, rawValue] = line.split(SPLIT_DELIMITER, 1);
// Strip out any in-line comments
const value = rawValue.split(COMMENT, 1);
const result = Env.set(variable.strip(), value[0].strip());
if (not result.success()) {
return result;
}
}
}
return Success(nil);
}