optparse-simple 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/optparse-simple.rb +32 -14
- metadata +43 -29
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37d6173b73bb275426106256fb2966cfde8a043e
|
4
|
+
data.tar.gz: 23a9c4497a816aebfa1e1d8849958c14b983aa45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7835d62d9ed19c9035889a0c9bdc941a2d784ce8dabf4d3f21ee235a44b48dee6bbdda72c7288aaf5e43ebe4e13c7b2c0eabb57fba1bafd0f59687c0764eb7b5
|
7
|
+
data.tar.gz: cb7a391852f0ce2a6badf87e6245cf7c5cc3bcb146f65f6dead3e2685dac300cf7a7b700ff7da8555cf26e4e62f09816118910e3425d77205cf0d599f1f50994
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/optparse-simple.rb
CHANGED
@@ -9,26 +9,28 @@ require 'table-formatter'
|
|
9
9
|
|
10
10
|
class OptParseSimple
|
11
11
|
include REXML
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(s)
|
14
14
|
super()
|
15
|
-
|
16
|
-
|
17
|
-
@doc = Document.new(buffer)
|
18
|
-
|
15
|
+
buffer = readx(s)
|
16
|
+
|
17
|
+
@doc = Document.new(buffer)
|
18
|
+
#@doc = Rexle.new(buffer)
|
19
19
|
end
|
20
20
|
|
21
21
|
def parse(args)
|
22
|
-
|
22
|
+
|
23
23
|
@options = XPath.match(@doc.root, 'records/optionx[summary/switch!="n/a"]')
|
24
|
+
#@options = @doc.root.xpath('records/optionx[summary/switch!="n/a"]')
|
25
|
+
|
26
|
+
switches = @options.map do |option|
|
24
27
|
|
25
|
-
switches = @options.map do |option|
|
26
28
|
switch = option.text('summary/switch')
|
27
29
|
switch[0] == '-' ? switch : nil
|
28
30
|
end
|
29
31
|
|
30
32
|
switches.compact!
|
31
|
-
|
33
|
+
|
32
34
|
# split the argument switches if grouped e.g. -ltr
|
33
35
|
args.map! do |arg|
|
34
36
|
|
@@ -44,6 +46,7 @@ class OptParseSimple
|
|
44
46
|
# -- bind any loose value to their argument
|
45
47
|
xpath = 'records/optionx/summary[switch != "n/a" and value != "n/a"]'
|
46
48
|
options = XPath.match(@doc.root, xpath)\
|
49
|
+
#options = @doc.root.xpath(xpath)\
|
47
50
|
.map {|node| %w(switch alias)\
|
48
51
|
.map{|x| node.text(x)}.compact}\
|
49
52
|
.flatten
|
@@ -56,15 +59,23 @@ class OptParseSimple
|
|
56
59
|
# -- end of bind any loose value to their argument
|
57
60
|
|
58
61
|
a1 = []
|
62
|
+
|
59
63
|
a1 = options_match(@options[0], args).flatten.each_slice(2).map {|x| x if x[0]}.compact unless @options.empty?
|
64
|
+
|
60
65
|
options_remaining = XPath.match(@doc.root, 'records/optionx/summary[switch="n/a"]/name/text()').map(&:to_s)
|
66
|
+
#options_remaining = @doc.root.xpath('records/optionx/summary[switch="n/a"]/name/text()').map(&:to_s)
|
61
67
|
mandatory_remaining = XPath.match(@doc.root, 'records/optionx/summary[switch="n/a" and mandatory="true"]/name/text()').map(&:to_s)
|
68
|
+
#mandatory_remaining = @doc.root.xpath('records/optionx/summary[switch="n/a" and mandatory="true"]/name/text()').map(&:to_s)
|
69
|
+
|
62
70
|
if mandatory_remaining.length > args.length then
|
71
|
+
|
63
72
|
missing_arg = (mandatory_remaining - args).first
|
64
73
|
option = XPath.first(@doc.root, "records/optionx[summary/name='#{missing_arg}']")
|
65
|
-
|
74
|
+
#option = @doc.root.element("records/optionx[summary/name='#{missing_arg}']")
|
75
|
+
|
76
|
+
raise option.text('records/errorx/summary/msg') || 'missing arg'
|
66
77
|
end
|
67
|
-
|
78
|
+
|
68
79
|
a2 = args.zip(options_remaining).map(&:reverse)
|
69
80
|
if a2.map(&:first).all? then
|
70
81
|
@h = Hash[*(a1+a2).map{|x,y| [x.to_s.strip.to_sym, y]}.flatten]
|
@@ -72,6 +83,7 @@ class OptParseSimple
|
|
72
83
|
invalid_option = a2.detect {|x,y| x.nil? }.last
|
73
84
|
raise "invalid option: %s not recognised" % invalid_option
|
74
85
|
end
|
86
|
+
|
75
87
|
@h
|
76
88
|
end
|
77
89
|
|
@@ -81,9 +93,10 @@ class OptParseSimple
|
|
81
93
|
|
82
94
|
def help
|
83
95
|
a = XPath.match(@doc.root, "records/optionx/summary[switch != 'n/a']").map do |summary|
|
96
|
+
#a = @doc.root.xpath("records/optionx/summary[switch != 'n/a']").map do |summary|
|
84
97
|
%w(switch alias).map {|x| summary.text x}
|
85
98
|
end
|
86
|
-
|
99
|
+
|
87
100
|
puts TableFormatter.new(source: a, border: false).to_s
|
88
101
|
end
|
89
102
|
|
@@ -114,6 +127,7 @@ class OptParseSimple
|
|
114
127
|
next_option = @options[1] if @options.length > 1
|
115
128
|
|
116
129
|
if next_arg != next_option then
|
130
|
+
|
117
131
|
# validate using the regex
|
118
132
|
value = next_arg[/#{value_pattern}/]
|
119
133
|
|
@@ -129,6 +143,7 @@ class OptParseSimple
|
|
129
143
|
end
|
130
144
|
|
131
145
|
else
|
146
|
+
|
132
147
|
args.delete_at(arg_index)
|
133
148
|
end
|
134
149
|
|
@@ -148,8 +163,9 @@ class OptParseSimple
|
|
148
163
|
[pair, next_pair]
|
149
164
|
end
|
150
165
|
|
151
|
-
def
|
152
|
-
|
166
|
+
def readx(s)
|
167
|
+
|
168
|
+
r = if s[/\s/] then
|
153
169
|
Polyrex.new('options/optionx[name,switch,alias,value,mandatory]/errorx[msg]').parse(s).to_xml
|
154
170
|
elsif s.is_a? Polyrex then
|
155
171
|
s.to_xml
|
@@ -158,8 +174,10 @@ class OptParseSimple
|
|
158
174
|
elsif s[/\</] # xml
|
159
175
|
s
|
160
176
|
else # local file
|
161
|
-
File.
|
177
|
+
File.read s
|
162
178
|
end
|
179
|
+
|
180
|
+
r
|
163
181
|
end
|
164
182
|
|
165
183
|
end
|
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.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,55 +10,69 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
14
|
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
-
|
15
|
+
8ixkARkWAmV1MB4XDTE1MDIwODE4MjQyN1oXDTE2MDIwODE4MjQyN1owSDESMBAG
|
16
16
|
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
17
|
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
-
|
19
|
-
+
|
20
|
-
|
21
|
-
|
22
|
-
+
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
ggEBAJLJE+iYKOrPhAmeZtKk4DD3mV8coX/pMgl3GExMZ3ABiGNA5wnraEeN1krx
|
19
|
+
q9cRIiEgO+llV+CDGWLd2oWBjo4u6LAhpCz2eQlJIbVyHu6qouKBTy4GbgVFg8Fn
|
20
|
+
8PLiFMB7wQoLoD8bG68AxxO2/iDQud4JlafEBXyxlTGuQlq5Lw9gQvSnlGAieRQr
|
21
|
+
NjuNIOw4n2HXRmivS4V+//zRPiyBGdhDbSB1zLIT7fgeIglEbDo21SQITTENRZ1h
|
22
|
+
DAkd4pmpisQWQAWy2Ov5r63uD9lpxSbHRFXyfaGaX3DMWpAhu10+JCc1Bo5kI2yk
|
23
|
+
hY4avOApo4rABOB/0PADod7JZ+ECAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUKuHNETC2YZlY8IaQxkLOu2+O10YwJgYDVR0RBB8w
|
25
|
+
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAPe03jlVt
|
27
|
+
HJlEqi5rwIcpo18mJFtU/9jcJt/3qlxN4966cs5sSCh96nMv0jLae/Y7a46OLwZG
|
28
|
+
MdF5SDcY3DCBJ7T+E+P2uuF17sx2NSZb/GDm90Z2rRhHnQCAyvCulBvE8lS8MjS8
|
29
|
+
dHzhwbn8Q2WvE4MDs/h8iGD+zW8DiSK1ltc+MWgHK/s9GyetV8S2/Gq6p9ejSZn+
|
30
|
+
HBHBh2QEqbXkwCsH5UllD93L2A8kyBEHzjuaO3CG1Yqj6d9xdCGzXr4vtXKVmBSd
|
31
|
+
reMUqAcVi3UK52Ugibv74I27D9zJTDYgqRMX3SevcEFrJo+g8ulq9nmVLQ3T+YB/
|
32
|
+
BlF5+4+5WNopaw==
|
31
33
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
34
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
33
35
|
dependencies:
|
34
36
|
- !ruby/object:Gem::Dependency
|
35
37
|
name: polyrex
|
36
38
|
requirement: !ruby/object:Gem::Requirement
|
37
39
|
requirements:
|
38
|
-
- -
|
40
|
+
- - "~>"
|
39
41
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
42
|
+
version: '0.9'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.3
|
41
46
|
type: :runtime
|
42
47
|
prerelease: false
|
43
48
|
version_requirements: !ruby/object:Gem::Requirement
|
44
49
|
requirements:
|
45
|
-
- -
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.9'
|
53
|
+
- - ">="
|
46
54
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
55
|
+
version: 0.9.3
|
48
56
|
- !ruby/object:Gem::Dependency
|
49
57
|
name: table-formatter
|
50
58
|
requirement: !ruby/object:Gem::Requirement
|
51
59
|
requirements:
|
52
|
-
- -
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.1'
|
63
|
+
- - ">="
|
53
64
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
65
|
+
version: 0.1.13
|
55
66
|
type: :runtime
|
56
67
|
prerelease: false
|
57
68
|
version_requirements: !ruby/object:Gem::Requirement
|
58
69
|
requirements:
|
59
|
-
- -
|
70
|
+
- - "~>"
|
60
71
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
72
|
+
version: '0.1'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.13
|
62
76
|
description: OptParse-Simple parses command-line arguments and returns them as a hash.
|
63
77
|
email: james@r0bertson.co.uk
|
64
78
|
executables: []
|
@@ -76,17 +90,17 @@ require_paths:
|
|
76
90
|
- lib
|
77
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
|
-
- -
|
93
|
+
- - ">="
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
95
|
+
version: 2.1.2
|
82
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
97
|
requirements:
|
84
|
-
- -
|
98
|
+
- - ">="
|
85
99
|
- !ruby/object:Gem::Version
|
86
100
|
version: '0'
|
87
101
|
requirements: []
|
88
102
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.2.2
|
90
104
|
signing_key:
|
91
105
|
specification_version: 4
|
92
106
|
summary: optparse-simple
|
metadata.gz.sig
CHANGED
Binary file
|