lab42_rgxargs 0.1.11 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lab42/rgxargs/checker.rb +2 -2
- data/lib/lab42/rgxargs/predefined_matchers.rb +1 -0
- data/lib/lab42/rgxargs/version.rb +1 -1
- data/lib/lab42/rgxargs.rb +58 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f5ad80ee90e6586a78c9ea98a1edbc211991425ad57779851c458270a24cdf
|
4
|
+
data.tar.gz: 424e5bd200042239c0f514dc148734a7ccfc6aa3b940d4f94ad2298e90b61e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fa3c37dc3763b9369a530db5df60bbcecc1524e856e6a5e74bf0067a2d1838a5e4fdb53c3e5b4a09ae097c216dab484dd5490b5f717ffbfeee7db49bd4ad676
|
7
|
+
data.tar.gz: '009c8e68f9acdf6ac1ca97a06a7e06e2c17c5f64419ff417ee197b907ce0867b07eb6dfb6c330a6f80a5c924021ea532131a2a4469189a23ddbe82c7d9458519'
|
@@ -15,7 +15,7 @@ module Lab42
|
|
15
15
|
missing = required - options.to_h.keys
|
16
16
|
@errors += missing.map(&_mk_pair(:required_kwd_missing))
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
|
20
20
|
def _mk_pair(prefix)
|
21
21
|
-> element do
|
@@ -24,7 +24,7 @@ module Lab42
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def _check_switch(_)
|
27
|
-
|
27
|
+
|
28
28
|
end
|
29
29
|
|
30
30
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Lab42::Rgxargs::PredefinedMatchers extend self
|
2
2
|
PREDEFINED = {
|
3
|
+
existing_dirs: [%r{(.+)}, ->(glob){ Dir.glob(glob).filter{ File.directory?(_1) } }],
|
3
4
|
int: [%r{\A([-+]?\d+)\z}, :to_i.to_proc],
|
4
5
|
int_list: [%r{\A(-?\d+(?:,-?\d+)*)\z}, ->(*groups){ groups.first.split(",").map(&:to_i)}],
|
5
6
|
int_range: [%r{\A(-?\d+)(?:-|\.\.)(-?\d+)\z}, ->(f, l){ Range.new(f.to_i, l.to_i) }],
|
data/lib/lab42/rgxargs.rb
CHANGED
@@ -18,7 +18,11 @@ module Lab42
|
|
18
18
|
extend Forwardable
|
19
19
|
def_delegators Predefined, :list_matcher
|
20
20
|
|
21
|
-
attr_reader :allowed, :args, :conversions, :defaults, :defined_rules, :errors, :options, :required, :syntaxes
|
21
|
+
attr_reader :allowed, :args, :conversions, :defaults, :defined_rules, :errors, :options, :posix, :required, :syntaxes
|
22
|
+
|
23
|
+
def predefined_matchers
|
24
|
+
Predefined.defined_names
|
25
|
+
end
|
22
26
|
|
23
27
|
|
24
28
|
def add_conversion(param, conversion=nil, required=nil, &block)
|
@@ -48,14 +52,13 @@ module Lab42
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def parse argv
|
51
|
-
|
52
|
-
|
55
|
+
if posix
|
56
|
+
_parse_posix argv
|
57
|
+
else
|
58
|
+
_parse_ruby_syntax argv
|
53
59
|
end
|
54
|
-
_check_required_kwds
|
55
|
-
[options, args, errors]
|
56
60
|
end
|
57
61
|
|
58
|
-
|
59
62
|
def allows name, matcher=nil, &converter
|
60
63
|
add_conversion(name, matcher, &converter)
|
61
64
|
end
|
@@ -66,13 +69,14 @@ module Lab42
|
|
66
69
|
|
67
70
|
private
|
68
71
|
|
69
|
-
def initialize &blk
|
72
|
+
def initialize(posix: false, &blk)
|
70
73
|
@args = []
|
71
74
|
@allowed = nil
|
72
75
|
@conversions = {}
|
73
76
|
@defaults = {}
|
74
77
|
@defined_rules = []
|
75
78
|
@errors = []
|
79
|
+
@posix = posix
|
76
80
|
@required = ::Set.new
|
77
81
|
@syntaxes = []
|
78
82
|
|
@@ -119,7 +123,16 @@ module Lab42
|
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
122
|
-
def
|
126
|
+
def _parse_next_posix argv
|
127
|
+
first, *rest = argv
|
128
|
+
if first == '--'
|
129
|
+
@args += rest
|
130
|
+
return []
|
131
|
+
end
|
132
|
+
_parse_posix_param first, rest
|
133
|
+
end
|
134
|
+
|
135
|
+
def _parse_next_ruby_syntax argv
|
123
136
|
first, *rest = argv
|
124
137
|
if first == '--'
|
125
138
|
@args += rest
|
@@ -128,6 +141,43 @@ module Lab42
|
|
128
141
|
_parse_symbolic first, rest
|
129
142
|
end
|
130
143
|
|
144
|
+
def _parse_posix argv
|
145
|
+
until argv.empty?
|
146
|
+
argv = _parse_next_posix argv
|
147
|
+
end
|
148
|
+
_check_required_kwds
|
149
|
+
[options, args, errors]
|
150
|
+
end
|
151
|
+
|
152
|
+
def _parse_posix_param first, rest
|
153
|
+
case first
|
154
|
+
when %r{\A--([-_[:alnum:]]+)=(.*)\z}
|
155
|
+
Regexp.last_match.to_a => _, name, value
|
156
|
+
name = name.gsub("-", "_")
|
157
|
+
options[name] = _convert(value, name: name)
|
158
|
+
when %r{\A--([-_[:alnum:]]+)\z}
|
159
|
+
Regexp.last_match.to_a => _, name
|
160
|
+
name = name.gsub("-", "_")
|
161
|
+
options[name] = true
|
162
|
+
when %r{\A-([[:alnum:]]+)\z}
|
163
|
+
$1.grapheme_clusters.each do |shopt|
|
164
|
+
options[shopt]=true
|
165
|
+
end
|
166
|
+
else
|
167
|
+
args << first
|
168
|
+
# _parse_syntax(first)
|
169
|
+
end
|
170
|
+
rest
|
171
|
+
end
|
172
|
+
|
173
|
+
def _parse_ruby_syntax argv
|
174
|
+
until argv.empty?
|
175
|
+
argv = _parse_next_ruby_syntax argv
|
176
|
+
end
|
177
|
+
_check_required_kwds
|
178
|
+
[options, args, errors]
|
179
|
+
end
|
180
|
+
|
131
181
|
def _parse_symbolic first, rest
|
132
182
|
case first
|
133
183
|
when %r{\A:(.*)}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_rgxargs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -94,14 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
97
|
+
version: 3.1.0
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.3.7
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Parse CL args according to regexen
|