diff --git a/.env b/.env index 56c4a3a..cec224b 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ -DB_HOST=localhost -DB_USER=db_user +DB_HOST=localhost +DB_USER=db_user DB_PASS=s1mpl3 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 79a071e..194c7ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,29 @@ -# Created by https://www.gitignore.io/api/matlab -# Edit at https://www.gitignore.io/?templates=matlab - -### MATLAB ### -# Windows default autosave extension -*.asv - -# OSX / *nix default autosave extension -*.m~ - -# Compiled MEX binaries (all platforms) -*.mex* - -# Packaged app and toolbox files -*.mlappinstall -*.mltbx - -# Generated helpsearch folders -helpsearch*/ - -# Simulink code generation folders -slprj/ -sccprj/ - -# Matlab code generation folders -codegen/ - -# Simulink autosave extension -*.autosave +# Created by https://www.gitignore.io/api/matlab +# Edit at https://www.gitignore.io/?templates=matlab + +### MATLAB ### +# Windows default autosave extension +*.asv + +# OSX / *nix default autosave extension +*.m~ + +# Compiled MEX binaries (all platforms) +*.mex* + +# Packaged app and toolbox files +*.mlappinstall +*.mltbx + +# Generated helpsearch folders +helpsearch*/ + +# Simulink code generation folders +slprj/ +sccprj/ + +# Matlab code generation folders +codegen/ + +# Simulink autosave extension +*.autosave diff --git a/README.md b/README.md index ddf244b..aa54937 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,63 @@ -# dotenv for MATLAB -> A MATLAB implementation of the dotenv pattern. - -Storing configuration in the environment separate from code is based on [The Twelve-Factor App](https://12factor.net/config) methodology. dotenv for MATLAB® lets you store configuration data (passwords, API keys, server names, etc.) outside of your code. This lets you share your code without sharing your configuration data. - -![screenshot](config/dotenv-screenshot.png "MATLAB Screenshot") - -[![mathworks](https://circleci.com/gh/mathworks/dotenv-for-MATLAB.svg?style=shield)](https://circleci.com/gh/mathworks/dotenv-for-MATLAB) - -[![View dotenv-for-MATLAB on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/73988-dotenv-for-matlab) -## Installation -Put `dotenv.m` somewhere on your [search path](https://www.mathworks.com/help/matlab/ref/path.html). - -## Usage Example -`dotenv()` will try and load a file named `.env` from the current working folder. Alternatively, you can specify the path with `dotenv('path/to/file.env')`. - -`.env` -```text -API_KEY=ybvxtzwaxa:r42DtRhuUT7TywYpzBABOFZ0IIomwuIEXnfFVq2VSXjRC -``` - -`file.m` -```matlab -d = dotenv(); -opts = weboptions('HeaderField', ["accept", "any"; "authorization", d.env.API_KEY]) -url = "https://myurl.com" -response = webread(url, opts); -``` -Common places you may need to do this are [`weboptions()`](https://www.mathworks.com/help/matlab/ref/weboptions.html), the [Database Toolbox](https://www.mathworks.com/help/database/ug/database.odbc.connection.html), or [`ftp()`](https://www.mathworks.com/help/matlab/ref/ftp.html). - -## Rules -The parsing engine currently supports the following rules: -* empty lines are skipped -* lines beginning with `#` are treated as comments -* empty values become empty strings (`DB_HOST=` becomes `DBHOST: ''`) -* whitespace is removed from both ends of unquoted values (`DB_HOST=some server` becomes `DB_HOST:'some server'`) -* quoted values are escaped (`DB_PASS=" some password "` becomes `DB_PASS:' some password '`) - -## FAQ -### Should I commit my `.env` file? -No. You should put `*.env` in your `.gitignore` file. - -## Development Setup -Clone the repository. You can run `runtests('tests')` from the project root to run the unit test suite. - -## Bugs? -I would love to hear if this breaks on any weird strings or doesn't work the way you expected. +# dotenv for MATLAB + +> A MATLAB implementation of dotenv + +Storing [configuration in the environment](https://12factor.net/config) is one of the tenets of a [12-factor app](https://12factor.net/). dotenv for MATLAB® lets you store configuration data (passwords, API keys, server names, etc.) outside of your code. This lets you share your code without sharing your configuration data. + +![screenshot](config/dotenv-compare.png "MATLAB Screenshot") + +[![mathworks](https://circleci.com/gh/mathworks/dotenv-for-MATLAB.svg?style=shield)](https://circleci.com/gh/mathworks/dotenv-for-MATLAB) + +[![View dotenv-for-MATLAB on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/73988-dotenv-for-matlab) + +## Installation + +Put `dotenv.m` somewhere on your [search path](https://www.mathworks.com/help/matlab/ref/path.html). + +## Usage Example + +`dotenv()` will try and load a file named `.env` from the current working folder. Alternatively, you can specify the path with `dotenv('path/to/file.env')`. + +`.env` + +```perl +# Obligatory XKCD https://xkcd.com/936/ +password=correct-horse-battery-staple +``` + +`file.m` + +```matlab +d = dotenv(); +opts = weboptions('HeaderField', ["accept", "any"; "authorization", d.env.password]) +url = "https://myurl.com" +response = webread(url, opts); +``` + +Common places you may need to do this are [`weboptions()`](https://www.mathworks.com/help/matlab/ref/weboptions.html), [working with remote data like S3 buckets](https://www.mathworks.com/help/matlab/import_export/work-with-remote-data.html), the [Database Toolbox](https://www.mathworks.com/help/database/ug/database.odbc.connection.html), or [`ftp()`](https://www.mathworks.com/help/matlab/ref/ftp.html). + +## Rules + +The parsing engine currently supports the following rules: + +* empty lines are skipped +* lines beginning with `#` are treated as comments +* empty values become empty strings (`DB_HOST=` becomes `DBHOST: ''`) +* whitespace is removed from both ends of unquoted values (`DB_HOST=some server` becomes `DB_HOST:'some server'`) +* quoted values are escaped (`DB_PASS=" some password "` becomes `DB_PASS:' some password '`) + +Examples are in the [config](config/) directory. + +## FAQ + +### Should I commit my `.env` file? + +No. You should put `*.env` in your `.gitignore` file. [MATLAB.gitignore](https://github.com/github/gitignore/blob/master/Global/MATLAB.gitignore) plus `*.env` is a good start. + +## Development Setup + +Clone the repository. You can run `runtests('tests')` from the project root to run the [unit test suite](tests/). + +## Bugs? + +I would love to hear if this breaks on any weird strings or doesn't work the way you expected. diff --git a/config/.env b/config/.env index b8050ea..7416ffc 100644 --- a/config/.env +++ b/config/.env @@ -1,4 +1,4 @@ -DB_HOST=localhost -DB_USER=root -DB_PASS=s1mpl3 +DB_HOST=localhost +DB_USER=root +DB_PASS=s1mpl3 #DB_COMMENT=comment \ No newline at end of file diff --git a/config/README.md b/config/README.md new file mode 100644 index 0000000..6e60a84 --- /dev/null +++ b/config/README.md @@ -0,0 +1,43 @@ +# Config files + +## [.env](.env) + +Shows basic functionality including the ability to comment out entries. + +## [blanklines.env](blanklines.env) + +Blank lines should be skipped. + +## [bottomcomment.env](bottomcomment.env) + +Comments should be ignored even if they're they last entry. + +## [empty.env](empty.env) + +A key doesn't have to have a value. `MYHOST=` should resolve to a kv pair of `'MYHOST': ''` + +## [equalPassword.env](equalPassword.env) + +If there is more than one `=` in an entry the kv pair splits on the first `=`. + +`DB_PASS=s1mpl3=123` resolves to a kv pair of `DB_PASS:s1mpl3=123`. **Not** `DB_PASS=s1mpl3: 123` + +## [middleComment.env](middleComment.env) + +Comments in the middle of a set of entries have no effect. Tests to ensure that succeeding entries still get processed. + +## [single.env](single.env) + +To test functonality for a single entry. + +## [specialchars.env](specialchars.env) + +Values with a space preserve the space. `DB_HOST=some server` becomes `DB_HOST:'some server'`. + +## [topcomment.env](topcomment.env) + +Comments should have no effect. Tests functionality if the first entry is commented out. + +## [whitespace.env](whitespace.env) + +Whitespace is ignored. diff --git a/config/blanklines.env b/config/blanklines.env index 56ad8df..c6eb1da 100644 --- a/config/blanklines.env +++ b/config/blanklines.env @@ -1,6 +1,6 @@ -DB_HOST=localhost - - -DB_USER=root -DB_PASS=s1mpl3 +DB_HOST=localhost + + +DB_USER=root +DB_PASS=s1mpl3 DB_COMMENT=comment \ No newline at end of file diff --git a/config/bottomcomment.env b/config/bottomcomment.env index b8050ea..7416ffc 100644 --- a/config/bottomcomment.env +++ b/config/bottomcomment.env @@ -1,4 +1,4 @@ -DB_HOST=localhost -DB_USER=root -DB_PASS=s1mpl3 +DB_HOST=localhost +DB_USER=root +DB_PASS=s1mpl3 #DB_COMMENT=comment \ No newline at end of file diff --git a/config/dotenv-compare.png b/config/dotenv-compare.png new file mode 100644 index 0000000..2ec5d17 Binary files /dev/null and b/config/dotenv-compare.png differ diff --git a/config/empty.env b/config/empty.env index 29fcef9..8ba8d87 100644 --- a/config/empty.env +++ b/config/empty.env @@ -1,2 +1,2 @@ -DB_HOST= +DB_HOST= DB_USER=gehrhorn \ No newline at end of file diff --git a/config/equalPassword.env b/config/equalPassword.env index 68e1d87..b96b831 100644 --- a/config/equalPassword.env +++ b/config/equalPassword.env @@ -1,4 +1,4 @@ -DB_HOST=localhost -DB_USER=root -DB_PASS=s1mpl3=123 +DB_HOST=localhost +DB_USER=root +DB_PASS=s1mpl3=123 DB_COMMENT=comment \ No newline at end of file diff --git a/config/middlecomment.env b/config/middlecomment.env index 795d7ac..c3cee25 100644 --- a/config/middlecomment.env +++ b/config/middlecomment.env @@ -1,4 +1,4 @@ -DB_HOST=localhost -#DB_USER=root -DB_PASS=s1mpl3 +DB_HOST=localhost +#DB_USER=root +DB_PASS=s1mpl3 DB_COMMENT=comment \ No newline at end of file diff --git a/config/specialchars.env b/config/specialchars.env index 207afd5..e13ec9c 100644 --- a/config/specialchars.env +++ b/config/specialchars.env @@ -1,2 +1,2 @@ -DB_HOST=localhost server +DB_HOST=localhost server DB_PASS=passhas=quote \ No newline at end of file diff --git a/config/topcomment.env b/config/topcomment.env index bb13690..f121535 100644 --- a/config/topcomment.env +++ b/config/topcomment.env @@ -1,4 +1,4 @@ -#DB_HOST=localhost -DB_USER=root -DB_PASS=s1mpl3 +#DB_HOST=localhost +DB_USER=root +DB_PASS=s1mpl3 DB_COMMENT=comment \ No newline at end of file diff --git a/config/whitespace.env b/config/whitespace.env index 58b5ffa..0bea67f 100644 --- a/config/whitespace.env +++ b/config/whitespace.env @@ -1,3 +1,3 @@ -DB_HOST=localhost server -DB_USER= george +DB_HOST=localhost server +DB_USER= george DB_PASS=" mypass " \ No newline at end of file diff --git a/dotenv for MATLAB.prj b/dotenv for MATLAB.prj index 0afc345..92c6696 100644 --- a/dotenv for MATLAB.prj +++ b/dotenv for MATLAB.prj @@ -1,2 +1,2 @@ - - + + diff --git a/dotenv.m b/dotenv.m index d9a7fc1..1429447 100644 --- a/dotenv.m +++ b/dotenv.m @@ -1,77 +1,90 @@ -classdef dotenv - % Dotenv Implementation of common dotenv pattern - % dotenv allows you to load environment variables at runtime without - % committing your .env file to source control. A common reason for - % doing this is that you need a password or API key but don't want to - % embed that in your code or in source control. - % See https://github.com/motdotla/dotenv for inspiration - % Copyright 2019-2019 The MathWorks, Inc. - - properties (SetAccess = immutable) - env % Structure to hold key/value pairs. Access via d.env.key. - end - - properties (Access = private) - fname - end - - - methods - function obj = dotenv(location) - % d = dotenv([path/to/file.env]) -- load .env file from current working directory or specified via path. - obj.env = struct; - switch nargin - case 1 % if there is an argument load that file - obj.fname = location; - case 0 % otherwise load the file from the current directory - obj.fname = '.env'; - end - - % ensure we can open the file - try - fid = fopen(obj.fname, 'r'); - assert(fid ~= -1); - catch - throw( MException('DOTENV:CannotOpenFile', "Cannot open file: " + obj.fname + ". Code: " + fid) ); - end - fclose(fid); - - % load the .env file with name=value pairs into the 'env' struct - lines = string(splitlines(fileread(obj.fname))); - - notOK = startsWith(lines, '#'); - lines(notOK) = []; - - expr = "(?.+?)=(?.*)"; - kvpair = regexp(lines, expr, 'names'); - - % Deal with single entry case where regexp does not return a - % cell array - if iscell(kvpair) - kvpair(cellfun(@isempty, kvpair)) = []; - kvpair = cellfun(@(x) struct('key', x.key, 'value', x.value), kvpair); - end - - obj.env = cell2struct(strtrim({kvpair.value}), [kvpair.key], 2); - - end - - function val = subsref(obj, s) - % Overload subsref to handle d.env (all key/value pairs vs. d.env.key (the value specified by the supplied key) - if size(s, 2) == 1 - % this handles the case of d.env - val=obj.env; - else - % this handles the case of d.env.KEY_NAME - if isfield(obj.env, s(2).subs) - val = obj.env.(s(2).subs); - else - val = ""; - end - end - end - - end - -end - +classdef dotenv + % Dotenv Implementation of dotenv pattern + % dotenv allows you to load environment variables at runtime without + % committing your .env file to source control. A common reason for + % doing this is that you need a password or API key but don't want to + % embed that in your code or in source control. + % See https://github.com/motdotla/dotenv for inspiration + % Copyright 2019-2021 The MathWorks, Inc. + + properties (SetAccess = immutable) + env % Structure to hold key/value pairs. Access via d.env.key. + end + + properties (Access = private) + fname + end + + + methods + function obj = dotenv(location) + % d = dotenv([path/to/file.env]) -- load .env file from current working directory or specified via path. + obj.env = struct; + switch nargin + case 1 % if there is an argument load that file + obj.fname = location; + case 0 % otherwise load the file from the current directory + obj.fname = '.env'; + end + + % ensure we can open the file + try + fid = fopen(obj.fname, 'r'); + assert(fid ~= -1); + catch + throw( MException('DOTENV:CannotOpenFile', "Cannot open file: " + obj.fname + ". Code: " + fid) ); + end + fclose(fid); + + % load the .env file with name=value pairs into the 'env' struct + % 20b (v9.10) introduced readlines() + if verLessThan('matlab', '9.10') + lines = string(splitlines(fileread(obj.fname))); + else + % I put in the feature request for readlines() so I better + % use it :) + lines = readlines(obj.fname); + end + + notOK = startsWith(lines, '#'); + lines(notOK) = []; + + % expr splits the line into a key / value pairs with regex + % capture. It captures one or more characters up to the first + % instance of an '=' in 'key' and then zero or more characters + % into 'value'. + expr = "(?.+?)=(?.*)"; + kvpair = regexp(lines, expr, 'names'); + + % Deal with single entry case where regexp does not return a + % cell array + if iscell(kvpair) + kvpair(cellfun(@isempty, kvpair)) = []; + kvpair = cellfun(@(x) struct('key', x.key, 'value', x.value), kvpair); + end + + % to be able to use dot reference we need to convert it to a + % structure + obj.env = cell2struct(strtrim({kvpair.value}), [kvpair.key], 2); + + end + + function val = subsref(obj, s) + % Overload subsref to handle d.env (all key/value pairs) vs. d.env.key (the value specified by the supplied key) + if size(s, 2) == 1 + % this handles the case of d.env + val=obj.env; + else + % this handles the case of d.env.KEY_NAME + if isfield(obj.env, s(2).subs) + val = obj.env.(s(2).subs); + else + val = ""; + end + end + end + + end + +end + diff --git a/license.txt b/license.txt index a51adaa..2bfd3ea 100644 --- a/license.txt +++ b/license.txt @@ -1,10 +1,10 @@ -Copyright (c) 2019, The MathWorks, Inc. -All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - +Copyright (c) 2019, The MathWorks, Inc. +All rights reserved. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + diff --git a/resources/project/Extensions.type.Root/Information.type.Extension.xml b/resources/project/Extensions.type.Root/Information.type.Extension.xml index f1c0cca..50af6b3 100644 --- a/resources/project/Extensions.type.Root/Information.type.Extension.xml +++ b/resources/project/Extensions.type.Root/Information.type.Extension.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Project.xml b/resources/project/Project.xml index 9806406..4a9e34e 100644 --- a/resources/project/Project.xml +++ b/resources/project/Project.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/ProjectData.type.Info.xml b/resources/project/ProjectData.type.Info.xml index b00922f..3f56bfd 100644 --- a/resources/project/ProjectData.type.Info.xml +++ b/resources/project/ProjectData.type.Info.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category.xml index 04b80f5..ef38945 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/artifact.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/artifact.type.Label.xml index a0b6797..b56f659 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/artifact.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/artifact.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/convenience.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/convenience.type.Label.xml index 894805d..5272801 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/convenience.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/convenience.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/derived.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/derived.type.Label.xml index a357dc8..5a873c8 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/derived.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/derived.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/design.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/design.type.Label.xml index bc411bf..59cb0be 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/design.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/design.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/none.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/none.type.Label.xml index 7622146..27ca3e7 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/none.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/none.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/other.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/other.type.Label.xml index 968d69b..14d104f 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/other.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/other.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Categories/FileClassCategory.type.Category/test.type.Label.xml b/resources/project/Root.type.Categories/FileClassCategory.type.Category/test.type.Label.xml index 8c2b952..5a6f802 100644 --- a/resources/project/Root.type.Categories/FileClassCategory.type.Category/test.type.Label.xml +++ b/resources/project/Root.type.Categories/FileClassCategory.type.Category/test.type.Label.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.EntryPointGroups/f8c886b5-f8d3-4640-8a84-2325ec11a40f.type.EntryPointGroup.xml b/resources/project/Root.type.EntryPointGroups/f8c886b5-f8d3-4640-8a84-2325ec11a40f.type.EntryPointGroup.xml index 25e0e47..04d16e1 100644 --- a/resources/project/Root.type.EntryPointGroups/f8c886b5-f8d3-4640-8a84-2325ec11a40f.type.EntryPointGroup.xml +++ b/resources/project/Root.type.EntryPointGroups/f8c886b5-f8d3-4640-8a84-2325ec11a40f.type.EntryPointGroup.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/.env.type.File.xml b/resources/project/Root.type.Files/.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/.env.type.File.xml +++ b/resources/project/Root.type.Files/.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/.gitignore.type.File.xml b/resources/project/Root.type.Files/.gitignore.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/.gitignore.type.File.xml +++ b/resources/project/Root.type.Files/.gitignore.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/README.md.type.File.xml b/resources/project/Root.type.Files/README.md.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/README.md.type.File.xml +++ b/resources/project/Root.type.Files/README.md.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File.xml b/resources/project/Root.type.Files/config.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/config.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/1.type.DIR_SIGNIFIER.xml b/resources/project/Root.type.Files/config.type.File/1.type.DIR_SIGNIFIER.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/config.type.File/1.type.DIR_SIGNIFIER.xml +++ b/resources/project/Root.type.Files/config.type.File/1.type.DIR_SIGNIFIER.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/blanklines.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/blanklines.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/blanklines.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/blanklines.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/bottomcomment.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/bottomcomment.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/bottomcomment.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/bottomcomment.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/dotenv-screenshot.png.type.File.xml b/resources/project/Root.type.Files/config.type.File/dotenv-screenshot.png.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/config.type.File/dotenv-screenshot.png.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/dotenv-screenshot.png.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/empty.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/empty.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/empty.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/empty.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/equalPassword.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/equalPassword.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/equalPassword.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/equalPassword.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/middlecomment.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/middlecomment.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/middlecomment.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/middlecomment.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/single.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/single.env.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/config.type.File/single.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/single.env.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/specialchars.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/specialchars.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/specialchars.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/specialchars.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/topcomment.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/topcomment.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/topcomment.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/topcomment.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/config.type.File/whitespace.env.type.File.xml b/resources/project/Root.type.Files/config.type.File/whitespace.env.type.File.xml index 89f7222..d9a9e30 100644 --- a/resources/project/Root.type.Files/config.type.File/whitespace.env.type.File.xml +++ b/resources/project/Root.type.Files/config.type.File/whitespace.env.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/dotenv.m.type.File.xml b/resources/project/Root.type.Files/dotenv.m.type.File.xml index afaafcc..80b5b16 100644 --- a/resources/project/Root.type.Files/dotenv.m.type.File.xml +++ b/resources/project/Root.type.Files/dotenv.m.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/license.txt.type.File.xml b/resources/project/Root.type.Files/license.txt.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/license.txt.type.File.xml +++ b/resources/project/Root.type.Files/license.txt.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tests.type.File.xml b/resources/project/Root.type.Files/tests.type.File.xml index c62f4b0..d8fadf3 100644 --- a/resources/project/Root.type.Files/tests.type.File.xml +++ b/resources/project/Root.type.Files/tests.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tests.type.File/.env.type.File.xml b/resources/project/Root.type.Files/tests.type.File/.env.type.File.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/tests.type.File/.env.type.File.xml +++ b/resources/project/Root.type.Files/tests.type.File/.env.type.File.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tests.type.File/1.type.DIR_SIGNIFIER.xml b/resources/project/Root.type.Files/tests.type.File/1.type.DIR_SIGNIFIER.xml index f14960e..1c0844e 100644 --- a/resources/project/Root.type.Files/tests.type.File/1.type.DIR_SIGNIFIER.xml +++ b/resources/project/Root.type.Files/tests.type.File/1.type.DIR_SIGNIFIER.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tests.type.File/fileTest.m.type.File.xml b/resources/project/Root.type.Files/tests.type.File/fileTest.m.type.File.xml index c62f4b0..d8fadf3 100644 --- a/resources/project/Root.type.Files/tests.type.File/fileTest.m.type.File.xml +++ b/resources/project/Root.type.Files/tests.type.File/fileTest.m.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tests.type.File/rulesTest.m.type.File.xml b/resources/project/Root.type.Files/tests.type.File/rulesTest.m.type.File.xml index c62f4b0..d8fadf3 100644 --- a/resources/project/Root.type.Files/tests.type.File/rulesTest.m.type.File.xml +++ b/resources/project/Root.type.Files/tests.type.File/rulesTest.m.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.Files/tests.type.File/valueRetrieveTest.m.type.File.xml b/resources/project/Root.type.Files/tests.type.File/valueRetrieveTest.m.type.File.xml index c62f4b0..d8fadf3 100644 --- a/resources/project/Root.type.Files/tests.type.File/valueRetrieveTest.m.type.File.xml +++ b/resources/project/Root.type.Files/tests.type.File/valueRetrieveTest.m.type.File.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/resources/project/Root.type.ProjectPath/077101fe-d6c5-492f-a597-59001c2d4176.type.Reference.xml b/resources/project/Root.type.ProjectPath/077101fe-d6c5-492f-a597-59001c2d4176.type.Reference.xml index dd31cfb..9a74e6c 100644 --- a/resources/project/Root.type.ProjectPath/077101fe-d6c5-492f-a597-59001c2d4176.type.Reference.xml +++ b/resources/project/Root.type.ProjectPath/077101fe-d6c5-492f-a597-59001c2d4176.type.Reference.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.ProjectPath/b715ba8c-e48c-49be-8727-c90cc30c4ae9.type.Reference.xml b/resources/project/Root.type.ProjectPath/b715ba8c-e48c-49be-8727-c90cc30c4ae9.type.Reference.xml index 4951d26..aa25c75 100644 --- a/resources/project/Root.type.ProjectPath/b715ba8c-e48c-49be-8727-c90cc30c4ae9.type.Reference.xml +++ b/resources/project/Root.type.ProjectPath/b715ba8c-e48c-49be-8727-c90cc30c4ae9.type.Reference.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/Root.type.ProjectPath/cd9851d8-0174-4f87-b435-d9f5e2bb0dbe.type.Reference.xml b/resources/project/Root.type.ProjectPath/cd9851d8-0174-4f87-b435-d9f5e2bb0dbe.type.Reference.xml index b1d8e4e..59b7a5d 100644 --- a/resources/project/Root.type.ProjectPath/cd9851d8-0174-4f87-b435-d9f5e2bb0dbe.type.Reference.xml +++ b/resources/project/Root.type.ProjectPath/cd9851d8-0174-4f87-b435-d9f5e2bb0dbe.type.Reference.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/resources/project/uuid-f9b4998b-e6e6-4342-90ba-a1b77c2a87b2.xml b/resources/project/uuid-f9b4998b-e6e6-4342-90ba-a1b77c2a87b2.xml index f14960e..1c0844e 100644 --- a/resources/project/uuid-f9b4998b-e6e6-4342-90ba-a1b77c2a87b2.xml +++ b/resources/project/uuid-f9b4998b-e6e6-4342-90ba-a1b77c2a87b2.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/tests/.env b/tests/.env index ddc0820..4b2bcd7 100644 --- a/tests/.env +++ b/tests/.env @@ -1,3 +1,3 @@ -DB_HOST=localhost -DB_USER=root +DB_HOST=localhost +DB_USER=root DB_PASS=s1mple \ No newline at end of file diff --git a/tests/fileTest.m b/tests/fileTest.m index bcff494..42d324b 100644 --- a/tests/fileTest.m +++ b/tests/fileTest.m @@ -1,22 +1,22 @@ -% Copyright 2019-2019 The MathWorks, Inc. - -function tests = fileTest -tests = functiontests(localfunctions); -end - -function testFileNotFound(testCase) -testCase.verifyError(@() dotenv('config/dotenv'), 'DOTENV:CannotOpenFile', ... - 'Should error properly for file that doesn''t exist'); -end - -function testDefaultLocation(testCase) -%% Opens default ./.env file -d = dotenv(); -testCase.verifyEqual(d.env.DB_HOST, "localhost"); -end - -function testNamedLocation(testCase) -%% Opens nested .env file -d = dotenv('../config/.env'); -testCase.verifyEqual(d.env.DB_HOST, "localhost"); +% Copyright 2019-2019 The MathWorks, Inc. + +function tests = fileTest +tests = functiontests(localfunctions); +end + +function testFileNotFound(testCase) +testCase.verifyError(@() dotenv('config/dotenv'), 'DOTENV:CannotOpenFile', ... + 'Should error properly for file that doesn''t exist'); +end + +function testDefaultLocation(testCase) +%% Opens default ./.env file +d = dotenv(); +testCase.verifyEqual(d.env.DB_HOST, "localhost"); +end + +function testNamedLocation(testCase) +%% Opens nested .env file +d = dotenv('../config/.env'); +testCase.verifyEqual(d.env.DB_HOST, "localhost"); end \ No newline at end of file diff --git a/tests/rulesTest.m b/tests/rulesTest.m index 6000c18..1d3e477 100644 --- a/tests/rulesTest.m +++ b/tests/rulesTest.m @@ -1,66 +1,66 @@ -% Copyright 2019-2019 The MathWorks, Inc. - -function tests = rulesTest() -%Rules Test tests expected behavoir of .env config -% See https://github.com/motdotla/dotenv#rules -tests = functiontests(localfunctions); -end - -function testTopComment(testCase) -% Tests that lines starting with # are skipped -% specifically tests first line comment -d = dotenv('../config/topcomment.env'); -testCase.verifyNumElements(fieldnames(d.env), 3); -end - -function testMiddleComment(testCase) -% Tests that lines starting with # are skipped -% specifically tests interior comment -d = dotenv('../config/middlecomment.env'); -testCase.verifyNumElements(fieldnames(d.env), 3); -end - -function testBottomComment(testCase) -% Tests that lines starting with # are skipped -% specifically tests last line comment -d = dotenv('../config/bottomcomment.env'); -testCase.verifyNumElements(fieldnames(d.env), 3); -end - -function testBlankLines(testCase) -d = dotenv('../config/blanklines.env'); -testCase.verifyNumElements(fieldnames(d.env), 4); -end - -function testEqualsInPassword(testCase) -d = dotenv('../config/equalPassword.env'); -testCase.verifyEqual("s1mpl3=123", d.env.DB_PASS); -end - -function testWhitespaceValue(testCase) -d = dotenv('../config/whitespace.env'); -testCase.verifyEqual("localhost server", d.env.DB_HOST); -end - -function testEmptyValue(testCase) -d = dotenv('../config/empty.env'); -testCase.verifyEqual(d.env.DB_HOST,""); -end - -function testUnquotedWhitespace(testCase) -% D.configure should trim leading and trailing whitespace for whitespace values -d = dotenv('../config/whitespace.env'); -testCase.verifyEqual(d.env.DB_USER, "george"); -end - -function testQuotedValues(testCase) -d = dotenv('../config/whitespace.env'); -testCase.verifyEqual(d.env.DB_PASS, """ mypass """); -end - -function testSingleValue(testCase) -d = dotenv('../config/single.env'); -testCase.verifyEqual(d.env.DB_HOST, "localhost"); -end - - +% Copyright 2019-2019 The MathWorks, Inc. + +function tests = rulesTest() +% Rules Test tests expected behavoir of .env config +% See https://github.com/motdotla/dotenv#rules +tests = functiontests(localfunctions); +end + +function testTopComment(testCase) +% Tests that lines starting with # are skipped +% specifically tests first line comment +d = dotenv('../config/topcomment.env'); +testCase.verifyNumElements(fieldnames(d.env), 3); +end + +function testMiddleComment(testCase) +% Tests that lines starting with # are skipped +% specifically tests interior comment +d = dotenv('../config/middlecomment.env'); +testCase.verifyNumElements(fieldnames(d.env), 3); +end + +function testBottomComment(testCase) +% Tests that lines starting with # are skipped +% specifically tests last line comment +d = dotenv('../config/bottomcomment.env'); +testCase.verifyNumElements(fieldnames(d.env), 3); +end + +function testBlankLines(testCase) +d = dotenv('../config/blanklines.env'); +testCase.verifyNumElements(fieldnames(d.env), 4); +end + +function testEqualsInPassword(testCase) +d = dotenv('../config/equalPassword.env'); +testCase.verifyEqual("s1mpl3=123", d.env.DB_PASS); +end + +function testWhitespaceValue(testCase) +d = dotenv('../config/whitespace.env'); +testCase.verifyEqual("localhost server", d.env.DB_HOST); +end + +function testEmptyValue(testCase) +d = dotenv('../config/empty.env'); +testCase.verifyEqual(d.env.DB_HOST,""); +end + +function testUnquotedWhitespace(testCase) +% D.configure should trim leading and trailing whitespace for whitespace values +d = dotenv('../config/whitespace.env'); +testCase.verifyEqual(d.env.DB_USER, "george"); +end + +function testQuotedValues(testCase) +d = dotenv('../config/whitespace.env'); +testCase.verifyEqual(d.env.DB_PASS, """ mypass """); +end + +function testSingleValue(testCase) +d = dotenv('../config/single.env'); +testCase.verifyEqual(d.env.DB_HOST, "localhost"); +end + + diff --git a/tests/valueRetrieveTest.m b/tests/valueRetrieveTest.m index 409bcb2..2eecb76 100644 --- a/tests/valueRetrieveTest.m +++ b/tests/valueRetrieveTest.m @@ -1,17 +1,17 @@ -% Copyright 2019-2019 The MathWorks, Inc. - -function tests = valueRetrieveTest -tests = functiontests(localfunctions); -end - - -function testValidData(testCase) -d = dotenv(); -testCase.verifyEqual(d.env.DB_HOST,"localhost"); -end - - -function testInvalidName(testCase) -d = dotenv(); -testCase.verifyEqual(d.env.DB_HOSED, "", 'DB_HOSED variable doesn''t exist'); -end +% Copyright 2019-2019 The MathWorks, Inc. + +function tests = valueRetrieveTest +tests = functiontests(localfunctions); +end + + +function testValidData(testCase) +d = dotenv(); +testCase.verifyEqual(d.env.DB_HOST,"localhost"); +end + + +function testInvalidName(testCase) +d = dotenv(); +testCase.verifyEqual(d.env.DB_HOSED, "", 'DB_HOSED variable doesn''t exist'); +end