lab42_rgxargs 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6f5ad80ee90e6586a78c9ea98a1edbc211991425ad57779851c458270a24cdf
4
- data.tar.gz: 424e5bd200042239c0f514dc148734a7ccfc6aa3b940d4f94ad2298e90b61e83
3
+ metadata.gz: fad5aa10d2f59f1463750eaf26714fa89c84c57bc1af8834467fcc5af041ae7c
4
+ data.tar.gz: 01f8276d9423596b87a88c6f9af13904bfc8df9b3c11ce7bcc4fef2121ca7bba
5
5
  SHA512:
6
- metadata.gz: 3fa3c37dc3763b9369a530db5df60bbcecc1524e856e6a5e74bf0067a2d1838a5e4fdb53c3e5b4a09ae097c216dab484dd5490b5f717ffbfeee7db49bd4ad676
7
- data.tar.gz: '009c8e68f9acdf6ac1ca97a06a7e06e2c17c5f64419ff417ee197b907ce0867b07eb6dfb6c330a6f80a5c924021ea532131a2a4469189a23ddbe82c7d9458519'
6
+ metadata.gz: c4d6c8d6d3324e96bbeafff6c232dbd21e28036ef49ab92b0c3d91f41d967c8fbf844c24bff30d2427bfe03709d73482fcdf0b4b2bea3d8bf582135be9e82f87
7
+ data.tar.gz: 6a0b083147b1f5c62ef82dc6b5769ba2fc1f5e744d6b1866ea1f002332fb5a0e47f28c11fab6f6ba53e89534e91f7e76db9ce6db380f9492076e1ae965f79af5
@@ -1,5 +1,7 @@
1
+ require 'l42/map'
2
+
1
3
  module Lab42
2
4
  class Rgxargs
3
- VERSION = "0.2.2"
5
+ VERSION = "0.3.1"
4
6
  end
5
7
  end
data/lib/lab42/rgxargs.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'forwardable'
2
- require 'ostruct'
3
2
  require 'lab42/enumerable'
4
3
  require 'set'
4
+
5
5
  module Lab42
6
6
 
7
7
  class Rgxargs
@@ -18,7 +18,7 @@ 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, :posix, :required, :syntaxes
21
+ attr_reader :allowed, :args, :conversions, :defaults, :defined_rules, :errors, :l42_map, :options, :posix, :required, :syntaxes
22
22
 
23
23
  def predefined_matchers
24
24
  Predefined.defined_names
@@ -69,7 +69,7 @@ module Lab42
69
69
 
70
70
  private
71
71
 
72
- def initialize(posix: false, &blk)
72
+ def initialize(l42_map: true, posix: false, &blk)
73
73
  @args = []
74
74
  @allowed = nil
75
75
  @conversions = {}
@@ -77,11 +77,12 @@ module Lab42
77
77
  @defined_rules = []
78
78
  @errors = []
79
79
  @posix = posix
80
+ @l42_map = l42_map
80
81
  @required = ::Set.new
81
82
  @syntaxes = []
82
83
 
83
84
  instance_exec(&blk) if blk
84
- @options = ::OpenStruct.new(defaults)
85
+ @options = defaults
85
86
  end
86
87
 
87
88
  def _convert(value, name:)
@@ -146,7 +147,7 @@ module Lab42
146
147
  argv = _parse_next_posix argv
147
148
  end
148
149
  _check_required_kwds
149
- [options, args, errors]
150
+ _return_values
150
151
  end
151
152
 
152
153
  def _parse_posix_param first, rest
@@ -154,14 +155,14 @@ module Lab42
154
155
  when %r{\A--([-_[:alnum:]]+)=(.*)\z}
155
156
  Regexp.last_match.to_a => _, name, value
156
157
  name = name.gsub("-", "_")
157
- options[name] = _convert(value, name: name)
158
+ options[name.to_sym] = _convert(value, name: name)
158
159
  when %r{\A--([-_[:alnum:]]+)\z}
159
160
  Regexp.last_match.to_a => _, name
160
161
  name = name.gsub("-", "_")
161
- options[name] = true
162
+ options[name.to_sym] = true
162
163
  when %r{\A-([[:alnum:]]+)\z}
163
164
  $1.grapheme_clusters.each do |shopt|
164
- options[shopt]=true
165
+ options[shopt.to_sym]=true
165
166
  end
166
167
  else
167
168
  args << first
@@ -175,7 +176,7 @@ module Lab42
175
176
  argv = _parse_next_ruby_syntax argv
176
177
  end
177
178
  _check_required_kwds
178
- [options, args, errors]
179
+ _return_values
179
180
  end
180
181
 
181
182
  def _parse_symbolic first, rest
@@ -183,7 +184,7 @@ module Lab42
183
184
  when %r{\A:(.*)}
184
185
  switch = $1.gsub('-','_').to_sym
185
186
  _check_switch(switch)
186
- options[switch]=true
187
+ options[switch.to_sym]=true
187
188
  rest
188
189
  when %r{(.*):\z}
189
190
  kwd = $1.gsub('-', '_').to_sym
@@ -201,7 +202,7 @@ module Lab42
201
202
  def _parse_syntax first
202
203
  value, as = syntaxes.find_value(first){ |matcher| matcher.match(first) }
203
204
  if as
204
- options[as] = value
205
+ options[as.to_sym] = value
205
206
  else
206
207
  args << value
207
208
  end
@@ -210,12 +211,19 @@ module Lab42
210
211
  def _parse_value name, rest
211
212
  value, *rest1 = rest
212
213
  if value
213
- options[name] = _convert(value, name: name)
214
+ options[name.to_sym] = _convert(value, name: name)
214
215
  return rest1
215
216
  end
216
217
  errors << [:missing_required_value, name]
217
218
  []
218
219
  end
219
220
 
221
+ def _return_values
222
+ if l42_map
223
+ [L42::Map.new(**options).with_default(nil), args, errors]
224
+ else
225
+ [options, args, errors]
226
+ end
227
+ end
220
228
  end
221
229
  end
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.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -11,61 +11,19 @@ cert_chain: []
11
11
  date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: speculate_about
14
+ name: l42_map
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
20
- type: :development
19
+ version: 0.1.1
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.9'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.9'
41
- - !ruby/object:Gem::Dependency
42
- name: pry-byebug
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.7'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.7'
55
- - !ruby/object:Gem::Dependency
56
- name: pry-doc
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
26
+ version: 0.1.1
69
27
  description: Parse CL args according to regexen
70
28
  email: robert.dober@gmail.com
71
29
  executables: []