dotenv 2.7.0 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dotenv/cli.rb +41 -16
- data/lib/dotenv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0992bc73a32f12b64e16572e15cbde78e9767730ed5aae4ea2e986e8ef98d81f'
|
4
|
+
data.tar.gz: 3c9209567d61c87b38a6077550a9c489f3b3b5d441c247ca6563a17ac91f3923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3109086cd8ad5b552bca4d4f219fe2a6e670eb66430c034010be2e8e60bda81c177e80f0a0c32be01c13c3509252d924e4aa40c4916039a9867c6801045eb64
|
7
|
+
data.tar.gz: 2b59d23bde10b3d1521b681aa04cad979d127c965610c1e9995f12b3e14fa4d0bbb6e56485fbe5ff2bf3cc3eb12fc8c16b156b59ea04c38b41f95ca73881c913
|
data/lib/dotenv/cli.rb
CHANGED
@@ -6,10 +6,12 @@ module Dotenv
|
|
6
6
|
# The CLI is a class responsible of handling all the command line interface
|
7
7
|
# logic.
|
8
8
|
class CLI
|
9
|
-
attr_reader :argv
|
9
|
+
attr_reader :argv, :exec_args, :parser_args, :filenames
|
10
10
|
|
11
11
|
def initialize(argv = [])
|
12
12
|
@argv = argv.dup
|
13
|
+
@filenames = []
|
14
|
+
@flag_matchers = []
|
13
15
|
end
|
14
16
|
|
15
17
|
def run
|
@@ -20,48 +22,71 @@ module Dotenv
|
|
20
22
|
rescue Errno::ENOENT => e
|
21
23
|
abort e.message
|
22
24
|
else
|
23
|
-
exec(*@
|
25
|
+
exec(*@exec_args) unless @exec_args.empty?
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
31
|
def parse_argv!(argv)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
parser.separator ""
|
35
|
-
add_options(parser)
|
36
|
-
end.parse!(argv)
|
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
|
37
36
|
|
38
37
|
@filenames
|
39
38
|
end
|
40
39
|
|
41
|
-
def add_options(parser)
|
42
|
-
add_files_option(parser)
|
43
|
-
add_help_option(parser)
|
44
|
-
add_version_option(parser)
|
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)
|
45
44
|
end
|
46
45
|
|
47
|
-
def add_files_option(parser)
|
46
|
+
def add_files_option(parser, flag_matchers)
|
47
|
+
flag_matchers.push("-f \\S+")
|
48
48
|
parser.on("-f FILES", Array, "List of env files to parse") do |list|
|
49
49
|
@filenames = list
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def add_help_option(parser)
|
53
|
+
def add_help_option(parser, flag_matchers)
|
54
|
+
flag_matchers.push("-h", "--help")
|
54
55
|
parser.on("-h", "--help", "Display help") do
|
55
56
|
puts parser
|
56
57
|
exit
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
60
|
-
def add_version_option(parser)
|
61
|
+
def add_version_option(parser, flag_matchers)
|
62
|
+
flag_matchers.push("-v", "--version")
|
61
63
|
parser.on("-v", "--version", "Show version") do
|
62
64
|
puts "dotenv #{Dotenv::VERSION}"
|
63
65
|
exit
|
64
66
|
end
|
65
67
|
end
|
68
|
+
|
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(" ") : [])
|
80
|
+
end
|
81
|
+
|
82
|
+
[dotenv_args, exec_args]
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_option_parser
|
86
|
+
OptionParser.new do |parser|
|
87
|
+
parser.banner = "Usage: dotenv [options]"
|
88
|
+
parser.separator ""
|
89
|
+
end
|
90
|
+
end
|
66
91
|
end
|
67
92
|
end
|
data/lib/dotenv/version.rb
CHANGED
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.
|
4
|
+
version: 2.7.1
|
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-
|
11
|
+
date: 2019-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|