You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C++ implementation of NodeJS [dotenv](https://github.com/motdotla/dotenv) project. Loads environment variables from `.env` for C++ projects.
4
6
5
7
**Please take into account this is still a developing project.**
6
8
@@ -12,6 +14,9 @@ C++ implementation of nodejs [dotenv](https://github.com/motdotla/dotenv) projec
12
14
2.[Usage](#usage)
13
15
1.[CMake](#cmake)
14
16
3.[Examples](#examples)
17
+
1.[Basic usage](#basic-usage)
18
+
2.[Reference renaming](#reference-renaming)
19
+
3.[Several dotenv files](#several-dotenv-files)
15
20
4.[Grammar](#grammar)
16
21
17
22
## Dependencies
@@ -34,6 +39,8 @@ using namespace dotenv;
34
39
35
40
For convenience, **cpp-dotenv** auto-configures a class object (which is instance of the singleton class `dotenv`) by calling the `load_dotenv()` method at the very beginning of your file (just right before the end of `dotenv.h`) and trying to load a `.env` file, although if you need to add-in your own files (like `.myenv`), simply re-run the loading step passing the file name as parameter; everything new will show up on the `dotenv` instances.
36
41
42
+
By default, already-defined environment variables are not overwritten even if redefined in some of the loaded files. This behavior can be changed, however, by calling the `load_config()` function with the `overwrite` parameter set to `true`. For an example, take a look at [this one](#several-dotenv-files).
43
+
37
44
Also for convenience, there is a namespace-global pre-loaded reference variable to the `dotenv` singleton class instance named `env`. Simply use it as you would use a dotenv object on NodeJS, or you can define your own references:
38
45
39
46
```cpp
@@ -56,6 +63,8 @@ After this, you might use the library as described in [usage](#usage); no extra
Assuming the same `.env` file as in the [previous case](#basic-usage), the predefined `env` reference can be easily renamed and used just exactly as the original one.
The situation of having several different dotenv files is no stranger one (`.env` for private configuration variables, `.pubenv` for public variables, etc.). Loading several files in addition to the default one and overwritting any variables that are redefined on the files can be done as follows:
For the geeks, you can check the grammar I've implemented on the `grammar/env.g4` file. Despite being written in an ANTLR4 fashion, I've implemented a simple recursive parser myself given the basic nature of the language. The parser and its methods are publicly available under the `dotenv::parser` class.
183
+
184
+
## Known issues
185
+
186
+
The complete list of issues con be consulted at the [issues page](https://github.com/adeharo9/cpp-dotenv/issues).
187
+
188
+
1.[Variable resolution on values not yet vailable](https://github.com/adeharo9/cpp-dotenv/issues/3)
0 commit comments