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 +4 -4
- data/README.md +2 -2
- data/lib/parse-argv/conversion.rb +3 -3
- data/lib/parse-argv/version.rb +1 -1
- data/lib/parse-argv.rb +9 -12
- 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: 338e91de84d8ed85aa324ecdbf33d370722213a90bc0e274a620e2ac08f908c8
|
4
|
+
data.tar.gz: 3996367a789b9dee75f2dbd91334e6b965897fb530611598ae715d2e5db29995
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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)
|
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)
|
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
|
data/lib/parse-argv/version.rb
CHANGED
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
|
169
|
-
@help.pop while @help
|
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
|
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.
|
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
|
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
|
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(
|
770
|
-
@options[checked_opt(
|
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.
|
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:
|
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
|
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.
|