dotenv 2.7.1 → 2.7.4

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: 32d793ec7a9658f9ba0430a02fd476f59a1419966beb9075f9d98cafcf3a1011
4
+ data.tar.gz: f90ee6fb4800d609d2b45c3e5fbb83deeab5233ed240d05f91653029b75a8bff
5
5
  SHA512:
6
- metadata.gz: c3109086cd8ad5b552bca4d4f219fe2a6e670eb66430c034010be2e8e60bda81c177e80f0a0c32be01c13c3509252d924e4aa40c4916039a9867c6801045eb64
7
- data.tar.gz: 2b59d23bde10b3d1521b681aa04cad979d127c965610c1e9995f12b3e14fa4d0bbb6e56485fbe5ff2bf3cc3eb12fc8c16b156b59ea04c38b41f95ca73881c913
6
+ metadata.gz: 99ecdc886adbb511fca292305f27f9eff8a6035a3ee266a358a61965d611f31fb1a9742b0662ac085d8112a45298b78b662336bc920de97b9da37818487a9417
7
+ data.tar.gz: a0b13a9af84d9870431dc42b1e206581f43dc3e3fe8b9f05ad573b5f5740fdf4844c372f8d96827a3f3b51bbe64bddc19ca7ca50895ff8af4d17abcc28a68d16
data/README.md CHANGED
@@ -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,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
@@ -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.1".freeze
2
+ VERSION = "2.7.4".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.4
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: 2019-06-24 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: