Merge pull request #307 from georgi-d/expandEnvVars
Added environment variable expansion support to the server config file
This commit is contained in:
commit
bfb3e6e9a4
|
@ -224,7 +224,11 @@ The server will attempt to read the file ```${XDG_CONFIG_HOME}/dcd/dcd.conf```
|
|||
```dcd.conf``` on Windows in the current working directory on startup.
|
||||
If it exists, each line of the file is interpreted as a path that should be
|
||||
searched when looking for module imports. Lines that start with the "#" character
|
||||
are ignored.
|
||||
are ignored. Lines can contain environment variables which will be expanded
|
||||
during loading. The name of the environment variable needs to the enclosed in
|
||||
${VAR}. For example:
|
||||
|
||||
${HOME}/sysroot/usr/include/dmd/phobos
|
||||
|
||||
Keep in mind that DCD treats import paths the same way that the compiler does.
|
||||
For example, a configuration file like this will not work as expected:
|
||||
|
|
|
@ -376,11 +376,29 @@ void warnAboutOldConfigLocation()
|
|||
}
|
||||
}
|
||||
|
||||
import std.regex : ctRegex;
|
||||
alias envVarRegex = ctRegex!(`\$\{([_a-zA-Z][_a-zA-Z 0-9]*)\}`);
|
||||
|
||||
private unittest
|
||||
{
|
||||
import std.regex : replaceAll;
|
||||
|
||||
enum input = `${HOME}/aaa/${_bb_b}/ccc`;
|
||||
|
||||
assert(replaceAll!(m => m[1])(input, envVarRegex) == `HOME/aaa/_bb_b/ccc`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads import directories from the configuration file
|
||||
*/
|
||||
string[] loadConfiguredImportDirs()
|
||||
{
|
||||
string expandEnvVars(string l)
|
||||
{
|
||||
import std.regex : replaceAll;
|
||||
return replaceAll!(m => environment.get(m[1], ""))(l, envVarRegex);
|
||||
}
|
||||
|
||||
warnAboutOldConfigLocation();
|
||||
immutable string configLocation = getConfigurationLocation();
|
||||
if (!configLocation.exists())
|
||||
|
@ -388,8 +406,10 @@ string[] loadConfiguredImportDirs()
|
|||
info("Loading configuration from ", configLocation);
|
||||
File f = File(configLocation, "rt");
|
||||
return f.byLine(KeepTerminator.no)
|
||||
.filter!(a => a.length > 0 && a[0] != '#' && existanceCheck(a))
|
||||
.filter!(a => a.length > 0 && a[0] != '#')
|
||||
.map!(a => a.idup)
|
||||
.map!(expandEnvVars)
|
||||
.filter!(a => existanceCheck(a))
|
||||
.array();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue