thor-addons 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/thor_addons/options.rb +19 -10
- data/lib/thor_addons/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe504337d71eb421b7e686edcaaf999deafb7628
|
4
|
+
data.tar.gz: 6289a2a15f4d44a9e69680834f8fffc4b9a7c7c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c1f13322c537f4302ece4d3b051ba4bd1e6d5edb1e1be3a7f4dd2c6f68a0c02db6073f39e44b519caad44560112ade00fdfdc902a5d60b92a6a8af6a0ef337
|
7
|
+
data.tar.gz: ba538f94df0b4df7ef4f781eccdb5c89f912a8fd2b4ba2679ee6ebb753e986f21e6b320e07a46c79b53165f68ce18fe0ee3d62f4aca20a047f5fa21d1dea8356
|
data/CHANGELOG.md
CHANGED
data/lib/thor_addons/options.rb
CHANGED
@@ -3,7 +3,7 @@ module ThorAddons
|
|
3
3
|
attr_reader :current_command_name, :defaults, :invoked_via_subcommand, :invocations
|
4
4
|
|
5
5
|
def initialize(args = [], local_options = {}, config = {})
|
6
|
-
@current_command_name = config[:current_command].name
|
6
|
+
@current_command_name = config[:current_command] ? config[:current_command].name : nil
|
7
7
|
@defaults = load_defaults(config.dup)
|
8
8
|
@invoked_via_subcommand = config[:invoked_via_subcommand]
|
9
9
|
@invocations = config[:invocations]
|
@@ -35,7 +35,7 @@ module ThorAddons
|
|
35
35
|
merge(new_options, options_from_env)
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
hash_with_indifferent_access(add_defaults(new_options))
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -55,16 +55,17 @@ module ThorAddons
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def options_from_env
|
58
|
+
opts = {}
|
58
59
|
defaults.keys.inject({}) do |memo, option|
|
59
60
|
env = option.to_s.upcase
|
60
|
-
|
61
|
+
opts[option] = ENV[env] unless ENV[env].nil?
|
61
62
|
|
62
|
-
|
63
|
-
memo[option] = ENV[envs_aliases[env]] unless ENV[envs_aliases[env]].nil?
|
64
|
-
end
|
63
|
+
next unless envs_aliases.keys.include?(env) && opts[option].nil? && ENV[envs_aliases[env]]
|
65
64
|
|
66
|
-
|
65
|
+
opts[option] = ENV[envs_aliases[env]]
|
67
66
|
end
|
67
|
+
|
68
|
+
hash_with_indifferent_access(opts)
|
68
69
|
end
|
69
70
|
|
70
71
|
def options_from_config(config_file)
|
@@ -75,17 +76,21 @@ module ThorAddons
|
|
75
76
|
|
76
77
|
data = YAML.load_file(config_file)
|
77
78
|
command_options = {}
|
79
|
+
global = data["global"] || {}
|
80
|
+
|
81
|
+
return hash_with_indifferent_access(global) if current_command_name.nil?
|
82
|
+
|
78
83
|
if invoked_via_subcommand
|
79
84
|
invocations.map { |k,v| v }.flatten.each do |subcommand|
|
80
85
|
next if data[subcommand].nil? || data[subcommand][current_command_name].nil?
|
81
86
|
|
82
87
|
command_options.merge!(data[subcommand][current_command_name])
|
83
88
|
end
|
89
|
+
else
|
90
|
+
command_options.merge!(data[current_command_name]) unless data[current_command_name].nil?
|
84
91
|
end
|
85
92
|
|
86
|
-
global
|
87
|
-
|
88
|
-
::Thor::CoreExt::HashWithIndifferentAccess.new(global.merge(command_options))
|
93
|
+
hash_with_indifferent_access(global.merge(command_options))
|
89
94
|
end
|
90
95
|
|
91
96
|
def add_defaults(hash)
|
@@ -123,5 +128,9 @@ module ThorAddons
|
|
123
128
|
memo
|
124
129
|
end
|
125
130
|
end
|
131
|
+
|
132
|
+
def hash_with_indifferent_access(hash)
|
133
|
+
::Thor::CoreExt::HashWithIndifferentAccess.new(hash)
|
134
|
+
end
|
126
135
|
end
|
127
136
|
end
|
data/lib/thor_addons/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor-addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacopo Scrinzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|