dotenv 2.7.1 → 2.7.6

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: '0992bc73a32f12b64e16572e15cbde78e9767730ed5aae4ea2e986e8ef98d81f'
4
- data.tar.gz: 3c9209567d61c87b38a6077550a9c489f3b3b5d441c247ca6563a17ac91f3923
3
+ metadata.gz: f9897791ad9e8b033e9bf66513f4f53bd1afb7fa2d925995bcd4f46c6edff8f7
4
+ data.tar.gz: 4bff08bdfbdc9f5709626ab2b46ed098d5c602ccfcb8063457f238dabf459f43
5
5
  SHA512:
6
- metadata.gz: c3109086cd8ad5b552bca4d4f219fe2a6e670eb66430c034010be2e8e60bda81c177e80f0a0c32be01c13c3509252d924e4aa40c4916039a9867c6801045eb64
7
- data.tar.gz: 2b59d23bde10b3d1521b681aa04cad979d127c965610c1e9995f12b3e14fa4d0bbb6e56485fbe5ff2bf3cc3eb12fc8c16b156b59ea04c38b41f95ca73881c913
6
+ metadata.gz: 9594d44181f64067dd47b0e4a86a534620aa09278774ad8c86f08bb6d2d35f45d27a724a16207aee9189f508e00f102686c562d85f2feffd45fe506b6451f828
7
+ data.tar.gz: 9352577bba48b8f713914b1688f17355fc543b4b004a918889ffc1a83dda939e60597ea49c6ef9f3aad7dfcc48fd837fefa4746dfa783088429ea96ffb7fbaed
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?
@@ -1,17 +1,17 @@
1
1
  require "dotenv"
2
2
  require "dotenv/version"
3
+ require "dotenv/template"
3
4
  require "optparse"
4
5
 
5
6
  module Dotenv
6
7
  # The CLI is a class responsible of handling all the command line interface
7
8
  # logic.
8
9
  class CLI
9
- attr_reader :argv, :exec_args, :parser_args, :filenames
10
+ attr_reader :argv, :filenames
10
11
 
11
12
  def initialize(argv = [])
12
13
  @argv = argv.dup
13
14
  @filenames = []
14
- @flag_matchers = []
15
15
  end
16
16
 
17
17
  def run
@@ -22,7 +22,7 @@ module Dotenv
22
22
  rescue Errno::ENOENT => e
23
23
  abort e.message
24
24
  else
25
- exec(*@exec_args) unless @exec_args.empty?
25
+ exec(*@argv) unless @argv.empty?
26
26
  end
27
27
  end
28
28
 
@@ -30,56 +30,44 @@ module Dotenv
30
30
 
31
31
  def parse_argv!(argv)
32
32
  parser = create_option_parser
33
- add_options(parser, @flag_matchers)
34
- @parser_args, @exec_args = split_argv(argv.join(" "), @flag_matchers)
35
- parser.parse! @parser_args
33
+ add_options(parser)
34
+ parser.order!(argv)
36
35
 
37
36
  @filenames
38
37
  end
39
38
 
40
- def add_options(parser, flag_matchers)
41
- add_files_option(parser, flag_matchers)
42
- add_help_option(parser, flag_matchers)
43
- add_version_option(parser, flag_matchers)
39
+ def add_options(parser)
40
+ add_files_option(parser)
41
+ add_help_option(parser)
42
+ add_version_option(parser)
43
+ add_template_option(parser)
44
44
  end
45
45
 
46
- def add_files_option(parser, flag_matchers)
47
- flag_matchers.push("-f \\S+")
46
+ def add_files_option(parser)
48
47
  parser.on("-f FILES", Array, "List of env files to parse") do |list|
49
48
  @filenames = list
50
49
  end
51
50
  end
52
51
 
53
- def add_help_option(parser, flag_matchers)
54
- flag_matchers.push("-h", "--help")
52
+ def add_help_option(parser)
55
53
  parser.on("-h", "--help", "Display help") do
56
54
  puts parser
57
55
  exit
58
56
  end
59
57
  end
60
58
 
61
- def add_version_option(parser, flag_matchers)
62
- flag_matchers.push("-v", "--version")
59
+ def add_version_option(parser)
63
60
  parser.on("-v", "--version", "Show version") do
64
61
  puts "dotenv #{Dotenv::VERSION}"
65
62
  exit
66
63
  end
67
64
  end
68
65
 
69
- # Detect dotenv flags vs executable args so we can parse properly and still
70
- # take advantage of OptionParser for dotenv flags
71
- def split_argv(arg_string, matchers)
72
- matcher = /^((?:#{matchers.join("|")})\s?)?(.+)?$/
73
- data = matcher.match(arg_string)
74
- dotenv_args = []
75
- exec_args = []
76
-
77
- unless data.nil?
78
- dotenv_args = (!data[1].nil? ? data[1].split(" ") : [])
79
- exec_args = (!data[2].nil? ? data[2].split(" ") : [])
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
80
70
  end
81
-
82
- [dotenv_args, exec_args]
83
71
  end
84
72
 
85
73
  def create_option_parser
@@ -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,21 @@
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
+ var, value = line.split("=")
13
+ is_a_comment = var.strip[0].eql?("#")
14
+ line_transform = value.nil? || is_a_comment ? line : "#{var}=#{var}"
15
+ env_template.puts line_transform
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = "2.7.1".freeze
2
+ VERSION = "2.7.6".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.1
4
+ version: 2.7.6
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-02-24 00:00:00.000000000 Z
11
+ date: 2020-07-11 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:
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
- rubygems_version: 3.0.1
96
+ rubygems_version: 3.0.3
96
97
  signing_key:
97
98
  specification_version: 4
98
99
  summary: Loads environment variables from `.env`.