cli_helper 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: c26800bd031cdd8dc5cb7e27d0772377797a2a19
4
- data.tar.gz: bcc1dbb15015453061e049813c8d050b521919bc
3
+ metadata.gz: 970583c4a48a1bf449f0175963d74582823ee95f
4
+ data.tar.gz: c01c2f4fe14edc456ff6693434a725419b0f9e0d
5
5
  SHA512:
6
- metadata.gz: 5e6ed5a90d9aea36b026a68603facfb02117724fb585c711eaf46d2b092e8914302b23bcb5d7891d35560c011813f0d350791487556fc92b739cf5b5ebb76c2f
7
- data.tar.gz: ae39b8892ef01b65d529cd852ac1fc5e5a24903a14008ffcc95edd6b110160c95eea4454409b4abf3970c545eda08d12bfdc145d910bf4075cd0e85186d823e2
6
+ metadata.gz: 9ca124bb2d25a1f8b11c6fc250542926ffa7e772fb1c6462865feee930bc9241016354bf49909a8e5c9aead7aea79fb38512c718e7ba9633d9a0e97df4ac54d2
7
+ data.tar.gz: acbbd43bbc7653fe5a0850b2fcc55c3be75cd7b888a2b4a9990cb1c8f82ace6dc1b71b9a18422a21d9791ffec204194dd9d00af08c3071943dcea89a2382f39c
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Most recent changes
4
4
 
5
+ ### v0.1.3
6
+
7
+ * added ability to process a directory of config files
8
+ * added ability to process a default set of config files that could get over-written by specific config files specified on the command line
9
+
5
10
  ### v0.1.2
6
11
 
7
12
  * replaced the parseconfig gem with the inifile gem -- this now enables the use of ERB in *.ini and *.txt config files
data/cli_helper.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "cli_helper"
7
- spec.version = '0.1.2'
7
+ spec.version = '0.1.3'
8
8
  spec.authors = ["Dewayne VanHoozer"]
9
9
  spec.email = ["dvanhoozer@gmail.com"]
10
10
 
data/example/cli_stub.rb CHANGED
@@ -9,10 +9,10 @@
9
9
 
10
10
  require 'awesome_print'
11
11
 
12
- require 'cli_helper'
12
+ require '../lib/cli_helper'
13
13
  include CliHelper
14
14
 
15
- configatron.version = '0.0.1' # the version of this utility program
15
+ configatron.version = '0.0.2' # the version of this utility program
16
16
  configatron.enable_config_files = true # default is false
17
17
  configatron.disable_help = false # default is false set true to remove the option
18
18
  configatron.disable_verbose = false # ditto
@@ -20,6 +20,23 @@ configatron.disable_debug = false # ditto
20
20
  configatron.disable_version = false # ditto
21
21
  configatron.suppress_errors = false # set to true to eat exceptions; unknown options added to arguments
22
22
 
23
+
24
+ # Sometimes you may have a few default config files that you
25
+ # want to apply before the command-line options. Do it like
26
+ # something like this:
27
+ %w[
28
+ ../tests/config/sample.yml
29
+ ../tests/config/sample.yml.erb
30
+ ].each do |dcf|
31
+ cli_helper_process_config_file(dcf)
32
+ end
33
+
34
+ # OR just pass a directory and all of the config files in the
35
+ # directory will be processed:
36
+
37
+ cli_helper_process_config_file('../tests/config')
38
+
39
+
23
40
  # HELP is extra stuff shown with usage. It is optional. You
24
41
  # can put anything you want into it. Since it is optional, it
25
42
  # can be completely left out of your program. This HELP text
data/lib/cli_helper.rb CHANGED
@@ -108,6 +108,66 @@ module CliHelper
108
108
  return an_ini_object.to_h
109
109
  end
110
110
 
111
+ def cli_helper_process_config_file(a_cf)
112
+ cf = String == a_cf.class ? Pathname.new(a_cf) : a_cf
113
+ if cf.directory?
114
+ cf.children.each do |ccf|
115
+ cli_helper_process_config_file(ccf)
116
+ end
117
+ return
118
+ end
119
+ unless cf.exist?
120
+ error "Config file is missing: #{cf}"
121
+ else
122
+ file_type = case cf.extname.downcase
123
+ when '.rb'
124
+ :ruby
125
+ when '.yml', '.yaml'
126
+ :yaml
127
+ when '.ini', '.txt'
128
+ :ini
129
+ when '.erb'
130
+ extname = cf.basename.to_s.downcase.gsub('.erb','').split('.').last
131
+ if %w[ yml yaml].include? extname
132
+ :yaml
133
+ elsif %w[ ini txt ].include? extname
134
+ :ini
135
+ elsif 'rb' == extname
136
+ warning 'MakesNoSenseToMe: *.rb.erb is not supported'
137
+ :unknown
138
+ else
139
+ :unknown
140
+ end
141
+ else
142
+ :unknown
143
+ end
144
+
145
+ case file_type
146
+ when :ruby
147
+ load cf
148
+ when :yaml
149
+ configatron.configure_from_hash(
150
+ config_file_hash = configatron.configure_from_hash(
151
+ cli_helper_process_yaml(
152
+ cli_helper_process_erb(cf.read)
153
+ )
154
+ )
155
+ )
156
+ when :ini
157
+ configatron.configure_from_hash(
158
+ configatron.configure_from_hash(
159
+ cli_helper_process_ini(
160
+ cli_helper_process_erb(cf.read)
161
+ )
162
+ )
163
+ )
164
+ else
165
+ error "Do not know how to parse this file: #{cf}"
166
+ end # case type_type
167
+ end # unless cf.exist? || cf.directory?
168
+ end # def cli_helper_process_config_file(cf)
169
+
170
+
111
171
  # Invoke Slop with common CLI parameters and custom
112
172
  # parameters provided via a block. Create '?'
113
173
  # for all boolean parameters that have a '--name' flag form.
@@ -157,64 +217,19 @@ module CliHelper
157
217
  yield(param) if block_given?
158
218
 
159
219
  if configatron.enable_config_files
160
- param.paths '--config', 'read config file(s) [*.rb, *.yml, *.ini]'
220
+ param.paths '--config', 'read config file(s) [*.rb, *.yml, *.ini, *.erb]'
161
221
  end
162
222
 
163
223
  parser = Slop::Parser.new(param, suppress_errors: configatron.suppress_errors)
164
224
  configatron.cli = parser.parse(ARGV)
165
225
 
166
- # TODO: DRY this conditional block
226
+ # NOTE: The config files are being process before the
227
+ # command line options in order for the command
228
+ # line options to over-write the values from the
229
+ # config files.
167
230
  if configatron.enable_config_files
168
-
169
231
  configatron.cli[:config].each do |cf|
170
- unless cf.exist? || cf.directory?
171
- error "Config file is missing: #{cf}"
172
- else
173
- file_type = case cf.extname.downcase
174
- when '.rb'
175
- :ruby
176
- when '.yml', '.yaml'
177
- :yaml
178
- when '.ini', '.txt'
179
- :ini
180
- when '.erb'
181
- extname = cf.basename.to_s.downcase.gsub('.erb','').split('.').last
182
- if %w[ yml yaml].include? extname
183
- :yaml
184
- elsif %w[ ini txt ].include? extname
185
- :ini
186
- elsif 'rb' == extname
187
- raise 'MakesNoSenseToMe: *.rb.erb is not supported'
188
- else
189
- :unknown
190
- end
191
- else
192
- :unknown
193
- end
194
-
195
- case file_type
196
- when :ruby
197
- load cf
198
- when :yaml
199
- configatron.configure_from_hash(
200
- config_file_hash = configatron.configure_from_hash(
201
- cli_helper_process_yaml(
202
- cli_helper_process_erb(cf.read)
203
- )
204
- )
205
- )
206
- when :ini
207
- configatron.configure_from_hash(
208
- configatron.configure_from_hash(
209
- cli_helper_process_ini(
210
- cli_helper_process_erb(cf.read)
211
- )
212
- )
213
- )
214
- else
215
- error "Do not know how to parse this file: #{cf}"
216
- end # case type_type
217
- end # unless cf.exist? || cf.directory?
232
+ cli_helper_process_config_file(cf)
218
233
  end # configatron.cli.config.each do |cf|
219
234
  end # if configatron.enable_config_files
220
235
 
@@ -203,7 +203,7 @@ Where:
203
203
 
204
204
  Program Options Are:
205
205
  -x, --xyxxy example MAGIC parameter
206
- --config read config file(s) [*.rb, *.yml, *.ini]
206
+ --config read config file(s) [*.rb, *.yml, *.ini, *.erb]
207
207
 
208
208
  Do you need some HELP?
209
209
  EOS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configatron
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  requirements: []
203
203
  rubyforge_project:
204
- rubygems_version: 2.4.6
204
+ rubygems_version: 2.4.4
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: An encapsulation of an integration of slop, nenv, inifile and configatron.