optparse-simple 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,10 +5,10 @@ class OptParseSimple
|
|
5
5
|
|
6
6
|
def initialize(filename, args)
|
7
7
|
doc = Document.new(File.open(filename,'r').read)
|
8
|
-
@options = XPath.match(doc.root, 'records/option[switch!=""]')
|
8
|
+
@options = XPath.match(doc.root, 'records/option[summary/switch!=""]')
|
9
9
|
|
10
10
|
switches = @options.map do |option|
|
11
|
-
switch = option.text('switch')
|
11
|
+
switch = option.text('summary/switch')
|
12
12
|
switch[0] == '-' ? switch : nil
|
13
13
|
end
|
14
14
|
|
@@ -27,7 +27,7 @@ class OptParseSimple
|
|
27
27
|
args.flatten!
|
28
28
|
|
29
29
|
a1 = options_match(@options[0], args).flatten.each_slice(2).map {|x| x if x[0]}.compact
|
30
|
-
options_remaining = XPath.match(doc.root, 'records/option[switch=""]/name/text()')
|
30
|
+
options_remaining = XPath.match(doc.root, 'records/option/summary[switch=""]/name/text()')
|
31
31
|
a2 = args.zip(options_remaining).map(&:reverse)
|
32
32
|
if a2.map(&:first).all? then
|
33
33
|
@h = Hash[*(a1+a2).map{|x,y| [x.to_s.to_sym, y]}.flatten]
|
@@ -45,14 +45,14 @@ class OptParseSimple
|
|
45
45
|
|
46
46
|
def options_match(option, args)
|
47
47
|
|
48
|
-
switch, switch_alias = option.text('switch'), option.text('alias')
|
48
|
+
switch, switch_alias = option.text('summary/switch'), option.text('summary/alias')
|
49
49
|
switch_pattern = switch_alias ? "(%s|%s)" % [switch, switch_alias] : switch
|
50
50
|
switch_matched, arg_index = args.each_with_index.detect {|x,j| x[/^#{switch_pattern}/]}
|
51
51
|
key, value = nil
|
52
52
|
|
53
53
|
if switch_matched then
|
54
54
|
|
55
|
-
value_pattern = option.text('value')
|
55
|
+
value_pattern = option.text('summary/value')
|
56
56
|
|
57
57
|
if value_pattern then
|
58
58
|
|
@@ -74,7 +74,7 @@ class OptParseSimple
|
|
74
74
|
if value then
|
75
75
|
args.delete_at(arg_index + 1)
|
76
76
|
else
|
77
|
-
raise option.text('
|
77
|
+
raise option.text('records/error[last()]/summary/msg')
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -86,11 +86,11 @@ class OptParseSimple
|
|
86
86
|
args.delete_at(arg_index)
|
87
87
|
end
|
88
88
|
|
89
|
-
key = option.text('name')
|
89
|
+
key = option.text('summary/name')
|
90
90
|
|
91
|
-
elsif option.text('mandatory').downcase == 'true' then
|
91
|
+
elsif option.text('summary/mandatory').downcase == 'true' then
|
92
92
|
|
93
|
-
raise option.text('
|
93
|
+
raise option.text('records/error/summary/msg')
|
94
94
|
|
95
95
|
end
|
96
96
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optparse-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-05-11 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,7 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- lib/
|
25
|
+
- lib/optparse-simple.rb
|
26
26
|
has_rdoc: true
|
27
27
|
homepage:
|
28
28
|
licenses: []
|