autoargs 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/autoargs/version.rb +1 -1
- data/lib/autoargs.rb +25 -12
- 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: b692c49b540de544d7f3d738aa3187acf9b15026
|
4
|
+
data.tar.gz: ff8053961c2f3cedd9a0f16fa24feb7b422eb859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f9213af79aa58eac52516eaff977e3dac62825637db6df82f2a2b41cc821ba6d5568367e02c03f455f099fa0fa2b3c9375822385ec2b4648e803353caec6f40
|
7
|
+
data.tar.gz: 22baba0e680bf8ca688e811709cb6d0ee0a0674c5a0fbabecb8de49fbf528c110b2a1ccb22ae868529122031daaa3f0fc90ab4fab070c53f28dd7fe4d9680d37
|
data/lib/autoargs/version.rb
CHANGED
data/lib/autoargs.rb
CHANGED
@@ -31,28 +31,41 @@ module Autoargs
|
|
31
31
|
.map do |arg| [arg.children[0], arg.children[1].children[0]] end
|
32
32
|
]
|
33
33
|
|
34
|
+
usage = [[caller_file],
|
35
|
+
args.map do |arg| "<" + arg.to_s + ">" end,
|
36
|
+
optargs.map do |optarg| "[" + optarg[:name].to_s + "=" + optarg[:default].inspect + "]" end,
|
37
|
+
kwoptargs.map do |name, default| "[--" + name.to_s + " " + default.inspect + "]" end
|
38
|
+
].flatten(1).join(" ")
|
39
|
+
|
34
40
|
argv_args = ARGV[0 ... args.length]
|
35
41
|
argv_optargs = ARGV[args.length ... args.length + optargs.length]
|
36
42
|
argv_kwoptargs = Hash[
|
37
43
|
(ARGV[args.length + optargs.length .. -1] || [])
|
38
44
|
.each_slice(2)
|
39
45
|
.map do |name_with_prefix, value|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
begin
|
47
|
+
raise "Expected argument " + name_with_prefix + " to start with --." unless name_with_prefix.start_with?("--")
|
48
|
+
raise "Expected value for argument " + name_with_prefix if value.nil?
|
49
|
+
name = name_with_prefix[2 .. -1]
|
50
|
+
raise name + " is not an option." unless kwoptargs.has_key?(name.to_sym)
|
51
|
+
[name.to_sym, value]
|
52
|
+
rescue Exception => e
|
53
|
+
puts(e.message)
|
54
|
+
puts
|
55
|
+
puts(usage)
|
56
|
+
abort
|
57
|
+
end
|
44
58
|
end
|
45
59
|
]
|
46
60
|
|
47
|
-
if argv_args.length < args.length
|
48
|
-
abort([[caller_file],
|
49
|
-
args.map do |arg| "<" + arg.to_s + ">" end,
|
50
|
-
optargs.map do |optarg| "[" + optarg[:name].to_s + "=" + optarg[:default].inspect + "]" end,
|
51
|
-
kwoptargs.map do |name, default| "[--" + name.to_s + " " + default.inspect + "]" end
|
52
|
-
].flatten(1).join(" "))
|
53
|
-
end
|
61
|
+
abort(usage) if argv_args.length < args.length
|
54
62
|
|
55
|
-
|
63
|
+
positionals = ARGV.slice(0, args.length + optargs.length)
|
64
|
+
if argv_kwoptargs.keys.length != 0
|
65
|
+
method.call(*positionals, **argv_kwoptargs)
|
66
|
+
else
|
67
|
+
method.call(*positionals)
|
68
|
+
end
|
56
69
|
end
|
57
70
|
end
|
58
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoargs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wendt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|