dorian-arguments 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/arguments +1 -1
- data/lib/dorian/arguments.rb +15 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f09e26d0411f7f84c04ddaab79c610688bbef8cde70168e382c7e5ba0806f318
|
4
|
+
data.tar.gz: cc1076eee8faf10974beac03a902bbf687b6877a347b729dd5a4156d817a9c9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cadb685adb75738e5c25f8deb35f4108a761ba8fbc960a40c9b9da975f83c01a866fa12fc2ecb14b15e7e279ef941a8a16a82ded81b0348f5e85dd3c9a398746
|
7
|
+
data.tar.gz: 98ff574b80ed6cd988418bab196d4a0753a6e14470af260c59323703620f142a80b5285f945a1004b82c046bf838caaa822c6fc55d83dfe124a70ac5e288e456
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bin/arguments
CHANGED
@@ -6,7 +6,7 @@ require "dorian/arguments"
|
|
6
6
|
parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
|
7
7
|
|
8
8
|
if parsed.options.version
|
9
|
-
abort File.read(File.expand_path("
|
9
|
+
abort File.read(File.expand_path("../VERSION", __dir__))
|
10
10
|
else
|
11
11
|
abort parsed.help
|
12
12
|
end
|
data/lib/dorian/arguments.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bigdecimal"
|
2
4
|
require "bigdecimal/util"
|
3
5
|
|
@@ -12,10 +14,10 @@ class Dorian
|
|
12
14
|
DECIMAL = "decimal"
|
13
15
|
|
14
16
|
DEFAULT_MULTIPLE = false
|
15
|
-
DEFAULT_ALIASES = []
|
17
|
+
DEFAULT_ALIASES = [].freeze
|
16
18
|
DEFAULT_TYPE = BOOLEAN
|
17
19
|
|
18
|
-
TYPES = [BOOLEAN, STRING, NUMBER, INTEGER, DECIMAL]
|
20
|
+
TYPES = [BOOLEAN, STRING, NUMBER, INTEGER, DECIMAL].freeze
|
19
21
|
|
20
22
|
DEFAULT = nil
|
21
23
|
|
@@ -25,9 +27,9 @@ class Dorian
|
|
25
27
|
NUMBER => /^[0-9.]+$/i,
|
26
28
|
INTEGER => /^[0-9]+$/i,
|
27
29
|
DECIMAL => /^[0-9.]+$/i
|
28
|
-
}
|
30
|
+
}.freeze
|
29
31
|
|
30
|
-
BOOLEANS = { "true" => true, "false" => false }
|
32
|
+
BOOLEANS = { "true" => true, "false" => false }.freeze
|
31
33
|
|
32
34
|
def initialize(**definition)
|
33
35
|
@definition = definition
|
@@ -40,7 +42,6 @@ class Dorian
|
|
40
42
|
def parse
|
41
43
|
arguments = ARGV
|
42
44
|
options = {}
|
43
|
-
files = []
|
44
45
|
|
45
46
|
definition.each do |key, value|
|
46
47
|
type, default, aliases = normalize(value)
|
@@ -59,8 +60,8 @@ class Dorian
|
|
59
60
|
|
60
61
|
if argument.include?("=")
|
61
62
|
argument.split("=", 2).last
|
62
|
-
elsif arguments[index + 1].to_s
|
63
|
-
indexes << index + 1
|
63
|
+
elsif arguments[index + 1].to_s&.match?(MATCHES.fetch(type))
|
64
|
+
indexes << (index + 1)
|
64
65
|
|
65
66
|
arguments[index + 1]
|
66
67
|
elsif type == BOOLEAN
|
@@ -70,7 +71,7 @@ class Dorian
|
|
70
71
|
end
|
71
72
|
end
|
72
73
|
end
|
73
|
-
.
|
74
|
+
.compact
|
74
75
|
|
75
76
|
indexes.sort.reverse.uniq.each { |index| arguments.delete_at(index) }
|
76
77
|
|
@@ -87,7 +88,10 @@ class Dorian
|
|
87
88
|
options = Struct.new(*options.keys).new(*options.values)
|
88
89
|
|
89
90
|
Struct.new(:arguments, :options, :files, :help).new(
|
90
|
-
arguments,
|
91
|
+
arguments,
|
92
|
+
options,
|
93
|
+
files,
|
94
|
+
help
|
91
95
|
)
|
92
96
|
end
|
93
97
|
|
@@ -98,7 +102,7 @@ class Dorian
|
|
98
102
|
BOOLEANS.fetch(value.downcase)
|
99
103
|
elsif type == INTEGER
|
100
104
|
value.to_i
|
101
|
-
elsif
|
105
|
+
elsif [DECIMAL, NUMBER].include?(type)
|
102
106
|
value.to_d
|
103
107
|
else
|
104
108
|
value
|
@@ -106,7 +110,7 @@ class Dorian
|
|
106
110
|
end
|
107
111
|
|
108
112
|
def help
|
109
|
-
message = "USAGE: #{$PROGRAM_NAME}\n"
|
113
|
+
message = "USAGE: #{File.basename($PROGRAM_NAME)}\n"
|
110
114
|
|
111
115
|
message += "\n" if definition.any?
|
112
116
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-arguments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|
@@ -46,9 +46,9 @@ require_paths:
|
|
46
46
|
- lib
|
47
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - '='
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
51
|
+
version: 3.3.4
|
52
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|