nub 0.0.41 → 0.0.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nub/commander.rb +39 -3
- 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: 289eea77b83026e03f76830c0ef68782f44fdb34237b4077e4a747e44a18e11b
|
4
|
+
data.tar.gz: f3605f50a0555a2cd8f5f452739a863fd421c07ecffa8bcfedd8548975eaaad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d003170c0aa05f00626d9587b666c0b66923ff4ad20401db1d39d18f7dc0f143bfbd438433f71890485e8b44ccabe3bb497cfcdd74d383fa6cb6853cc842b87
|
7
|
+
data.tar.gz: 41a27d08399b97a8af5da53acfd63f1b62f7137d143c46cdd783a2947126dbc37d48060ff01b5a4aade8b97c82b3d72b9534b58bd68123fff4134f60ed6cb6e3
|
data/lib/nub/commander.rb
CHANGED
@@ -194,14 +194,50 @@ class Commander
|
|
194
194
|
@cmds[ARGV.shift.to_sym] = {}
|
195
195
|
cmd_names.reject!{|x| x == cmd.name}
|
196
196
|
|
197
|
-
#
|
198
|
-
opts = ARGV.take_while{|x| !cmd_names.include?(x) }
|
199
|
-
ARGV.shift(opts.size)
|
197
|
+
# Command options as defined in configuration
|
200
198
|
cmd_pos_opts = cmd.opts.select{|x| x.key.nil? }
|
201
199
|
cmd_named_opts = cmd.opts.select{|x| !x.key.nil? }
|
200
|
+
|
201
|
+
# Collect command options from args to compare against
|
202
|
+
opts = ARGV.take_while{|x| !cmd_names.include?(x) }
|
203
|
+
ARGV.shift(opts.size)
|
204
|
+
|
205
|
+
# All positional options are required. If they are not given then check for the 'chained
|
206
|
+
# command expression' case for positional options in the next command that satisfy the
|
207
|
+
# previous command's requirements and so on and so forth.
|
208
|
+
if opts.size == 0 && (cmd_pos_opts.any? || cmd_named_opts.any?{|x| x.required})
|
209
|
+
i = 0
|
210
|
+
while (i += 1) < ARGV.size do
|
211
|
+
opts = ARGV[i..-1].take_while{|x| !cmd_names.include?(x) }
|
212
|
+
break if opts.any?
|
213
|
+
end
|
214
|
+
|
215
|
+
# Check that the chained command options at least match types and size
|
216
|
+
if opts.any?
|
217
|
+
cmd_required = cmd.opts.select{|x| x.key.nil? || x.required}
|
218
|
+
other = @config.find{|x| x.name == ARGV[i-1]}
|
219
|
+
other_required = other.opts.select{|x| x.key.nil? || x.required}
|
220
|
+
|
221
|
+
!puts("Error: chained commands must have equal numbers of required optiosn".colorize(:red)) && !puts(cmd.help) and
|
222
|
+
exit if cmd_required.size != other_required.size
|
223
|
+
cmd_required.each_with_index{|x,i|
|
224
|
+
!puts("Error: chained command options are not type consistent".colorize(:red)) && !puts(cmd.help) and
|
225
|
+
exit if x.type != other_required[i].type || x.key != other_required[i].key
|
226
|
+
}
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Check that all positional options were given
|
202
231
|
!puts("Error: positional option required".colorize(:red)) && !puts(cmd.help) and
|
203
232
|
exit if opts.size < cmd_pos_opts.size
|
204
233
|
|
234
|
+
# Check that all required named options where given
|
235
|
+
named_opts = opts.select{|x| x.start_with?('-')}
|
236
|
+
cmd_named_opts.select{|x| x.required}.each{|x|
|
237
|
+
!puts("Error: required option #{x.key} not given".colorize(:red)) && !puts(cmd.help) and
|
238
|
+
exit if !named_opts.find{|y| y.start_with?(x.short) || y.start_with?(x.long)}
|
239
|
+
}
|
240
|
+
|
205
241
|
# Process command options
|
206
242
|
pos = -1
|
207
243
|
loop {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.42
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Crummett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|