parse-argv 0.1.1 → 0.1.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: a6ade60bea3be62e63a736037b26ba47ec41cb112d2465c311d8599bac72752c
4
- data.tar.gz: 936d92158e5f3904e53a6888211a09fc677c27e2e55d7dec4fbe6ce95a6a64fe
3
+ metadata.gz: 338e91de84d8ed85aa324ecdbf33d370722213a90bc0e274a620e2ac08f908c8
4
+ data.tar.gz: 3996367a789b9dee75f2dbd91334e6b965897fb530611598ae715d2e5db29995
5
5
  SHA512:
6
- metadata.gz: d3a9a75606f6efb1eb9cdf1df2017b1b34478b84610c4029083ace63897944cbc39574b74747a31e0cd1b979cf056cc623dc78f0f0dd9e8a5670206f794af048
7
- data.tar.gz: 1d192bef806f1d9c54c11f2f01b36b9ea7aa623f2610831ea1b7c5162f3a7f906e66a0574d4870f724c75a55de2b0353fd809076d127301bef056c936465189b
6
+ metadata.gz: 363d4e96f547b4b159c8fac299aff5debe080ab3fb51f46b2933d84c63143d3af940d0d943a212bcf28097eab2a123d67f372b42529fe7e90ba99c850564daf9
7
+ data.tar.gz: a0203a1c9a6d149f8f8e273b41ae8799786f439e637272c27ca2ee02481e1e06dece246f6d50f4ed1684adadf2fc88b3914180726f473d835a316fc5271566c6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ParseArgv
1
+ # ParseArgv ![version](https://img.shields.io/gem/v/parse-argv?label=)
2
2
 
3
3
  A command line parser that only needs your help text.
4
4
 
@@ -38,7 +38,7 @@ will be interpreted as
38
38
 
39
39
  ## How To Use
40
40
 
41
- Please, see the [Gem's help](https://rubydoc.info/gems/parse-argv) for detailed information, or have a look at the [`./examples`](./examples) directory which contains some commands to play around.
41
+ Please, see the [Gem's help](https://rubydoc.info/gems/parse-argv/ParseArgv) for detailed information, or have a look at the [`./examples`](./examples) directory which contains some commands to play around.
42
42
 
43
43
  The supported help text syntax and the command line interface syntax are described in the [syntax help](./syntax.md).
44
44
 
@@ -168,7 +168,7 @@ module ParseArgv
168
168
  def [](type)
169
169
  return regexp_match(type) if type.is_a?(Regexp)
170
170
  if type.is_a?(Array) && type.size == 1
171
- return array_of(Conversion[type.first])
171
+ return array_of(Conversion[type[0]])
172
172
  end
173
173
  return enum_type(type) if type.is_a?(Enumerable)
174
174
  (@ll[type] || @ll[type.to_sym]) or
@@ -324,7 +324,7 @@ module ParseArgv
324
324
  define(Array, :array)
325
325
 
326
326
  define(:date) do |arg, reference: nil, &err|
327
- defined?(::Date) || require('date')
327
+ defined?(::Date) or require('date')
328
328
  ret = Date._parse(arg)
329
329
  err['argument must be a date'] if ret.empty?
330
330
  reference ||= Date.today
@@ -339,7 +339,7 @@ module ParseArgv
339
339
  defined?(::Date) && define(Date, :date)
340
340
 
341
341
  define(:time) do |arg, reference: nil, &err|
342
- defined?(::Date) || require('date')
342
+ defined?(::Date) or require('date')
343
343
  ret = Date._parse(arg)
344
344
  err['argument must be a time'] if ret.empty?
345
345
  reference ||= Date.today
@@ -4,5 +4,5 @@ module ParseArgv
4
4
  #
5
5
  # current version
6
6
  #
7
- VERSION = '0.1.1'
7
+ VERSION = '0.1.2'
8
8
  end
data/lib/parse-argv.rb CHANGED
@@ -97,8 +97,7 @@ module ParseArgv
97
97
  # @return [ParseArgv] itself
98
98
  #
99
99
  def self.on_error(function = nil, &block)
100
- function ||= block
101
- return @on_error if function.nil?
100
+ function ||= block or return @on_error
102
101
  @on_error = function == :raise ? nil : function
103
102
  self
104
103
  end
@@ -165,8 +164,8 @@ module ParseArgv
165
164
  # @return [String] help text of the command
166
165
  def help
167
166
  return @help if @help.is_a?(String)
168
- @help.shift while @help.first&.empty?
169
- @help.pop while @help.last&.empty?
167
+ @help.shift while @help[0]&.empty?
168
+ @help.pop while @help[-1]&.empty?
170
169
  @help = @help.join("\n").freeze
171
170
  end
172
171
 
@@ -355,7 +354,7 @@ module ParseArgv
355
354
  name = name.to_sym
356
355
  value = @args[name]
357
356
  return value unless value.nil?
358
- args.empty? ? (block || ATTRIBUTE_ERROR).call(name) : args.first
357
+ args.empty? ? (block || ATTRIBUTE_ERROR).call(name) : args[0]
359
358
  end
360
359
 
361
360
  #
@@ -424,7 +423,7 @@ module ParseArgv
424
423
  # # String of format option or nil, when not specified
425
424
  #
426
425
  def method_missing(sym, *args)
427
- args.size.zero? or
426
+ args.empty? or
428
427
  raise(
429
428
  ArgumentError,
430
429
  "wrong number of arguments (given #{args.size}, expected 0)"
@@ -496,7 +495,7 @@ module ParseArgv
496
495
  args = @argv.take_while { |arg| arg[0] != '-' }
497
496
  return @main if args.empty?
498
497
  found = find_command(args)
499
- found.nil? ? raise(InvalidCommandError.new(@main, args.first)) : found
498
+ found.nil? ? raise(InvalidCommandError.new(@main, args[0])) : found
500
499
  end
501
500
 
502
501
  def find_command(args)
@@ -715,7 +714,7 @@ module ParseArgv
715
714
  keys = @arguments.keys.reverse!
716
715
  while argv.size < @arguments.size
717
716
  nonreq = keys.find { |key| @arguments[key][0] == 'o' }
718
- nonreq or raise(ArgumentMissingError.new(self, @arguments.keys.last))
717
+ nonreq or raise(ArgumentMissingError.new(self, @arguments.keys[-1]))
719
718
  @arguments.delete(keys.delete(nonreq))
720
719
  @result[nonreq] = nil
721
720
  end
@@ -766,10 +765,8 @@ module ParseArgv
766
765
  checked(name, DoublicateOptionDefinitionError)
767
766
  end
768
767
 
769
- def option(match)
770
- @options[checked_opt(match[1])] = @options[
771
- checked_opt(match[2])
772
- ] = match[3]
768
+ def option(mtc)
769
+ @options[checked_opt(mtc[1])] = @options[checked_opt(mtc[2])] = mtc[3]
773
770
  end
774
771
 
775
772
  def simple_option(match)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-argv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2023-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Just write the help text for your application and ParseArgv will take care
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.3.26
66
+ rubygems_version: 3.4.3
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: A command line parser that only needs your help text.