ArgvParser 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/argv_parser.rb +24 -12
- metadata +2 -2
data/lib/argv_parser.rb
CHANGED
@@ -27,7 +27,8 @@ class ArgvParser
|
|
27
27
|
(@l_short-k.length).times { spaces << " " }
|
28
28
|
spaces2 = ""
|
29
29
|
(@l_long-v[:long].length).times { spaces2 << " " }
|
30
|
-
puts "#{k}#{spaces} #{v[:long]}#{spaces2} mandatory:
|
30
|
+
puts "#{k}#{spaces} #{v[:long]}#{spaces2} mandatory: \
|
31
|
+
#{v[:opts][:mandatory] == true}"
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -42,27 +43,38 @@ class ArgvParser
|
|
42
43
|
end
|
43
44
|
|
44
45
|
while i < args.length
|
45
|
-
|
46
|
-
|
46
|
+
k = args[i].downcase
|
47
|
+
v = i+1 < args.length ? args[i+1] : nil
|
48
|
+
hook = @args[k]
|
49
|
+
if !hook and !v
|
50
|
+
hook = @args["--"]
|
51
|
+
v = k
|
52
|
+
k = "--"
|
53
|
+
end
|
54
|
+
|
55
|
+
if hook
|
56
|
+
@mandatory.delete(k)
|
47
57
|
|
48
58
|
n = nil
|
49
|
-
if
|
50
|
-
|
59
|
+
if hook[:type]
|
60
|
+
unless v
|
61
|
+
raise ArgumentError.new("argument for #{k} missing")
|
62
|
+
end
|
51
63
|
i += 1
|
52
|
-
case
|
64
|
+
case hook[:type].to_s
|
53
65
|
when "Array"
|
54
|
-
n =
|
66
|
+
n = v.split ','
|
55
67
|
when "Float"
|
56
|
-
n =
|
68
|
+
n = v.to_f
|
57
69
|
when "Integer"
|
58
|
-
n =
|
70
|
+
n = v.to_i
|
59
71
|
else
|
60
|
-
n = $1 if
|
72
|
+
n = $1 if v =~ /^\"?(.*)\"?$/
|
61
73
|
end
|
62
74
|
end
|
63
|
-
executor.push [
|
75
|
+
executor.push [hook[:yield], n]
|
64
76
|
else
|
65
|
-
raise ArgumentError.new("argument #{
|
77
|
+
raise ArgumentError.new("argument #{k} unknown")
|
66
78
|
end
|
67
79
|
i += 1
|
68
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ArgvParser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|