lab42_rgxargs 0.2.1 → 0.2.2

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: b9f2ee6bdaddb5db512e1cf55c65f42699b2441ac0878760f44c8083ff12f023
4
- data.tar.gz: 8e4175e4906cc5b5a3511f413b96f27f63cf7eaeaec7c07fe5e851ee2faa6e08
3
+ metadata.gz: f6f5ad80ee90e6586a78c9ea98a1edbc211991425ad57779851c458270a24cdf
4
+ data.tar.gz: 424e5bd200042239c0f514dc148734a7ccfc6aa3b940d4f94ad2298e90b61e83
5
5
  SHA512:
6
- metadata.gz: 33a12fa2ce1f98386d28bdd1c99a18fc982545fb26030c5a6dd618f5ce75e2276dfc06f91a4c9bbe6bb6867550be9a9a2aa95ca18d67244f4c3861409d4d58fe
7
- data.tar.gz: 022b992b251e8027bb19e1a91810abc066fac549b4d74ff77d43ecfa3c8ceae7bd41311b3161d7f7546ba187673307385c522f272a677aa0e81c54250c4ca0af
6
+ metadata.gz: 3fa3c37dc3763b9369a530db5df60bbcecc1524e856e6a5e74bf0067a2d1838a5e4fdb53c3e5b4a09ae097c216dab484dd5490b5f717ffbfeee7db49bd4ad676
7
+ data.tar.gz: '009c8e68f9acdf6ac1ca97a06a7e06e2c17c5f64419ff417ee197b907ce0867b07eb6dfb6c330a6f80a5c924021ea532131a2a4469189a23ddbe82c7d9458519'
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  class Rgxargs
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
data/lib/lab42/rgxargs.rb CHANGED
@@ -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, :required, :syntaxes
21
+ attr_reader :allowed, :args, :conversions, :defaults, :defined_rules, :errors, :options, :posix, :required, :syntaxes
22
22
 
23
23
  def predefined_matchers
24
24
  Predefined.defined_names
@@ -52,11 +52,11 @@ module Lab42
52
52
  end
53
53
 
54
54
  def parse argv
55
- until argv.empty?
56
- argv = _parse_next argv
55
+ if posix
56
+ _parse_posix argv
57
+ else
58
+ _parse_ruby_syntax argv
57
59
  end
58
- _check_required_kwds
59
- [options, args, errors]
60
60
  end
61
61
 
62
62
  def allows name, matcher=nil, &converter
@@ -69,13 +69,14 @@ module Lab42
69
69
 
70
70
  private
71
71
 
72
- def initialize &blk
72
+ def initialize(posix: false, &blk)
73
73
  @args = []
74
74
  @allowed = nil
75
75
  @conversions = {}
76
76
  @defaults = {}
77
77
  @defined_rules = []
78
78
  @errors = []
79
+ @posix = posix
79
80
  @required = ::Set.new
80
81
  @syntaxes = []
81
82
 
@@ -122,7 +123,16 @@ module Lab42
122
123
  end
123
124
  end
124
125
 
125
- def _parse_next argv
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
126
136
  first, *rest = argv
127
137
  if first == '--'
128
138
  @args += rest
@@ -131,6 +141,43 @@ module Lab42
131
141
  _parse_symbolic first, rest
132
142
  end
133
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
+
134
181
  def _parse_symbolic first, rest
135
182
  case first
136
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubygems_version: 3.3.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