Support lines starting with export
This commit is contained in:
parent
701d7f2a80
commit
2e24114804
4 changed files with 9 additions and 4 deletions
|
@ -20,6 +20,9 @@ defmodule DotenvParser do
|
||||||
* `\\\\` - Backslash
|
* `\\\\` - Backslash
|
||||||
* `\\uFFFF` - Unicode escape (4 hex characters to denote the codepoint)
|
* `\\uFFFF` - Unicode escape (4 hex characters to denote the codepoint)
|
||||||
|
|
||||||
|
A line can start with `export ` for easier interoperation with regular shell scripts. These lines are treated the
|
||||||
|
same as any others.
|
||||||
|
|
||||||
## Serving suggestion
|
## Serving suggestion
|
||||||
|
|
||||||
If you load lots of environment variables in `config/runtime.exs`, you can easily configure them for development by
|
If you load lots of environment variables in `config/runtime.exs`, you can easily configure them for development by
|
||||||
|
@ -38,7 +41,7 @@ defmodule DotenvParser do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@linefeed_re ~R/\r?\n/
|
@linefeed_re ~R/\r?\n/
|
||||||
@line_re ~R/^\s*[a-z_][a-z_0-9]*\s*=/i
|
@line_re ~R/^(?:\s*export)?\s*[a-z_][a-z_0-9]*\s*=/i
|
||||||
@dquoted_val_re ~R/^\s*"(.*)(?!\\)"\s*(?:#.*)?$/
|
@dquoted_val_re ~R/^\s*"(.*)(?!\\)"\s*(?:#.*)?$/
|
||||||
@squoted_val_re ~R/^\s*'(.*)(?!\\)'\s*(?:#.*)?$/
|
@squoted_val_re ~R/^\s*'(.*)(?!\\)'\s*(?:#.*)?$/
|
||||||
@hex_re ~R/^[0-9a-f]+$/i
|
@hex_re ~R/^[0-9a-f]+$/i
|
||||||
|
@ -114,7 +117,7 @@ defmodule DotenvParser do
|
||||||
raise ParseError, "Malformed line cannot be parsed: #{line}"
|
raise ParseError, "Malformed line cannot be parsed: #{line}"
|
||||||
else
|
else
|
||||||
[var, val] = String.split(line, "=", parts: 2)
|
[var, val] = String.split(line, "=", parts: 2)
|
||||||
var = String.trim(var)
|
var = var |> String.trim() |> String.replace_leading("export ", "")
|
||||||
val = String.trim(val)
|
val = String.trim(val)
|
||||||
|
|
||||||
with {:dquoted, nil} <- {:dquoted, Regex.run(@dquoted_val_re, val)},
|
with {:dquoted, nil} <- {:dquoted, Regex.run(@dquoted_val_re, val)},
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -4,7 +4,7 @@ defmodule DotenvParser.MixProject do
|
||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
app: :dotenv_parser,
|
app: :dotenv_parser,
|
||||||
version: "1.0.0",
|
version: "1.1.0",
|
||||||
elixir: "~> 1.11",
|
elixir: "~> 1.11",
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
|
|
|
@ -29,3 +29,4 @@ INLINE_COMMENT="foo#bar" # Bark Bark
|
||||||
INLINE_COMMENT_PLAIN=foo bar # Bark Bark
|
INLINE_COMMENT_PLAIN=foo bar # Bark Bark
|
||||||
END_BACKSLASH="something\" # Comment
|
END_BACKSLASH="something\" # Comment
|
||||||
lowercased_var=foo
|
lowercased_var=foo
|
||||||
|
export FOO="exports are supported"
|
||||||
|
|
|
@ -30,7 +30,8 @@ defmodule DotenvParserTest do
|
||||||
{"INLINE_COMMENT", "foo#bar"},
|
{"INLINE_COMMENT", "foo#bar"},
|
||||||
{"INLINE_COMMENT_PLAIN", "foo bar"},
|
{"INLINE_COMMENT_PLAIN", "foo bar"},
|
||||||
{"END_BACKSLASH", "something\\"},
|
{"END_BACKSLASH", "something\\"},
|
||||||
{"lowercased_var", "foo"}
|
{"lowercased_var", "foo"},
|
||||||
|
{"FOO", "exports are supported"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue