dotenv 2.7.2 → 2.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9da8f2d53f6ac0a52f98d5e5c8ae9a2bf80556737a2a040cb0d21f1e6dd94b5
4
- data.tar.gz: 973029ac871fe3e7880c91a812d2140a570c1298dfced693820ce10f877e40de
3
+ metadata.gz: 4ae9316b6ae85fca9d3c5724f6179127fa17444b94ba27ea1000fd5677e73249
4
+ data.tar.gz: da1ac6f6c94bda168a504f58244dd382012fa60ca56ba9dc44524bccc1a687b8
5
5
  SHA512:
6
- metadata.gz: 50390ce0eb353dd3baf5c3a42391e57c5f75dc216dc965e5dd07ec508196a75e52fedf15747389a7d403568f127929b62c1d190467c3b60a578270a76e396991
7
- data.tar.gz: 3ea3c50031729d18f21d619f17f7463ceb9a5409415e97b84bd98038dcf2f1ba44f6a9cd884fbc4f3c61cf408b1fd5ebafdf9f4939231acae388e232d28bbfd8
6
+ metadata.gz: b3fe0a0048d061128625f85f7f475a4f5a2d2e296906d108225275384ff22e249adc7a1e59e3f3585a912279796de06b9606dc842311e3c43c47de92561f6f99
7
+ data.tar.gz: 420e753ad539b9eabc26e7b13997d0b7272ccf1c4ec1b42f2455c2531976ec07514be88ca7fd691b422c4534f46ec0de77af7a86d6220b4cf0af2c11fbc0dff4
data/README.md CHANGED
@@ -62,7 +62,7 @@ Dotenv.load
62
62
 
63
63
  By default, `load` will look for a file called `.env` in the current working directory. Pass in multiple files and they will be loaded in order. The first value set for a variable will win.
64
64
 
65
- ```
65
+ ```ruby
66
66
  require 'dotenv'
67
67
  Dotenv.load('file1.env', 'file2.env')
68
68
  ```
@@ -218,6 +218,29 @@ If you use this gem to handle env vars for multiple Rails environments (developm
218
218
 
219
219
  Credentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server.
220
220
 
221
+
222
+ You can use the `-t` or `--template` flag on the dotenv cli to create a template of your `.env` file.
223
+ ```shell
224
+ $ dotenv -t .env
225
+ ```
226
+ A template will be created in your working directory named `{FINAME}.template`. So in the above example, it would create a `.env.template` file.
227
+
228
+ The template will contain all the environment variables in your `.env` file but with their values set to the variable names.
229
+
230
+ ```shell
231
+ # .env
232
+ S3_BUCKET=YOURS3BUCKET
233
+ SECRET_KEY=YOURSECRETKEYGOESHERE
234
+ ```
235
+
236
+ Would become
237
+
238
+ ```shell
239
+ # .env.template
240
+ S3_BUCKET=S3_BUCKET
241
+ SECRET_KEY=SECRET_KEY
242
+ ```
243
+
221
244
  Personally, I prefer to commit the `.env` file with development-only settings. This makes it easy for other developers to get started on the project without compromising credentials for other environments. If you follow this advice, make sure that all the credentials for your development environment are different from your other deployments and that the development credentials do not have access to any confidential data.
222
245
 
223
246
  ### Why is it not overriding existing `ENV` variables?
data/lib/dotenv/cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "dotenv"
2
2
  require "dotenv/version"
3
+ require "dotenv/template"
3
4
  require "optparse"
4
5
 
5
6
  module Dotenv
@@ -39,6 +40,7 @@ module Dotenv
39
40
  add_files_option(parser)
40
41
  add_help_option(parser)
41
42
  add_version_option(parser)
43
+ add_template_option(parser)
42
44
  end
43
45
 
44
46
  def add_files_option(parser)
@@ -61,6 +63,13 @@ module Dotenv
61
63
  end
62
64
  end
63
65
 
66
+ def add_template_option(parser)
67
+ parser.on("-t", "--template=FILE", "Create a template env file") do |file|
68
+ template = Dotenv::EnvTemplate.new(file)
69
+ template.create_template
70
+ end
71
+ end
72
+
64
73
  def create_option_parser
65
74
  OptionParser.new do |parser|
66
75
  parser.banner = "Usage: dotenv [options]"
data/lib/dotenv/parser.rb CHANGED
@@ -12,21 +12,21 @@ module Dotenv
12
12
  [Dotenv::Substitutions::Variable, Dotenv::Substitutions::Command]
13
13
 
14
14
  LINE = /
15
- (?:^|\A) # beginning of line
16
- \s* # leading whitespace
17
- (?:export\s+)? # optional export
18
- ([\w\.]+) # key
19
- (?:\s*=\s*?|:\s+?) # separator
20
- ( # optional value begin
21
- '(?:\\'|[^'])*' # single quoted value
22
- | # or
23
- "(?:\\"|[^"])*" # double quoted value
24
- | # or
25
- [^\#\r\n]+ # unquoted value
26
- )? # value end
27
- \s* # trailing whitespace
28
- (?:\#.*)? # optional comment
29
- (?:$|\z) # end of line
15
+ (?:^|\A) # beginning of line
16
+ \s* # leading whitespace
17
+ (?:export\s+)? # optional export
18
+ ([\w\.]+) # key
19
+ (?:\s*=\s*?|:\s+?) # separator
20
+ ( # optional value begin
21
+ \s*'(?:\\'|[^'])*' # single quoted value
22
+ | # or
23
+ \s*"(?:\\"|[^"])*" # double quoted value
24
+ | # or
25
+ [^\#\r\n]+ # unquoted value
26
+ )? # value end
27
+ \s* # trailing whitespace
28
+ (?:\#.*)? # optional comment
29
+ (?:$|\z) # end of line
30
30
  /x
31
31
 
32
32
  class << self
@@ -0,0 +1,19 @@
1
+ module Dotenv
2
+ # Class for creating a template from a env file
3
+ class EnvTemplate
4
+ def initialize(env_file)
5
+ @env_file = env_file
6
+ end
7
+
8
+ def create_template
9
+ File.open(@env_file, "r") do |env_file|
10
+ File.open("#{@env_file}.template", "w") do |env_template|
11
+ env_file.each do |line|
12
+ variable = line.split("=").first
13
+ env_template.puts "#{variable}=#{variable}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = "2.7.2".freeze
2
+ VERSION = "2.7.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-25 00:00:00.000000000 Z
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -72,6 +72,7 @@ files:
72
72
  - lib/dotenv/substitutions/command.rb
73
73
  - lib/dotenv/substitutions/variable.rb
74
74
  - lib/dotenv/tasks.rb
75
+ - lib/dotenv/template.rb
75
76
  - lib/dotenv/version.rb
76
77
  homepage: https://github.com/bkeepers/dotenv
77
78
  licenses: