-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from dictu-lang/feature/env_read_file
Env.readFile()
- Loading branch information
Showing
12 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ dictu.ilk | |
dictu.pdb | ||
test1.du | ||
.vscode/ | ||
/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#define DICTU_ENV_SOURCE "import Env;\n" \ | ||
"\n" \ | ||
"def readFile(path='.env') {\n" \ | ||
" const SPLIT_DELIMITER = '=';\n" \ | ||
" const COMMENT = '#';\n" \ | ||
"\n" \ | ||
" with(path, 'r') {\n" \ | ||
" var line;\n" \ | ||
" var lineCount = 0;\n" \ | ||
" // When you reach the end of the file, nil is returned\n" \ | ||
" while((line = file.readLine()) != nil) {\n" \ | ||
" lineCount = lineCount + 1;\n" \ | ||
" if (not line or line.startsWith(COMMENT))\n" \ | ||
" continue;\n" \ | ||
"\n" \ | ||
" if (not line.contains('='))\n" \ | ||
" return Error('Malformed entry on line {}'.format(lineCount));\n" \ | ||
"\n" \ | ||
" const [variable, rawValue] = line.split(SPLIT_DELIMITER, 1);\n" \ | ||
" // Strip out any in-line comments\n" \ | ||
" const value = rawValue.split(COMMENT, 1);\n" \ | ||
" const result = Env.set(variable.strip(), value[0].strip());\n" \ | ||
"\n" \ | ||
" if (not result.success()) {\n" \ | ||
" return result;\n" \ | ||
" }\n" \ | ||
" }\n" \ | ||
" }\n" \ | ||
"\n" \ | ||
" return Success(nil);\n" \ | ||
"}\n" \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
TEST=10 | ||
INLINE=100 # in-line comment | ||
# IGNORE=1000 | ||
SPACES = 30 | ||
MALFORMED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters