dorian-arguments 1.0.1 → 1.1.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/lib/dorian/arguments.rb +22 -10
- metadata +1 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9954bfae6d2589acc531515399fd72719c17e59850945789eda577bbdbf76a1
|
4
|
+
data.tar.gz: a515bd1890f8bb0f69f7851b17a3e2e7c81a347ff3bdd0043d9de6f5978b375d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f162d7069cce665ddafef2c864e4cfb97e367303624bcfa9fedd9539c0f1776292bb5b52073b0cd202e2a713b27ff18c3db53950f38008a4b54f81640db57cdf
|
7
|
+
data.tar.gz: e45aaa64ba83d4c43e7b1cc08115556ded6942de9a2d85b16d1bf2b106870703347922558d5e99afdedbe65d89c1c2dcb26890d9552a645d5e136fc32bb21f1e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/dorian/arguments.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
require "dorian/to_struct"
|
2
1
|
require "bigdecimal"
|
3
2
|
require "bigdecimal/util"
|
4
|
-
require "active_support"
|
5
|
-
require "active_support/core_ext/string/inflections"
|
6
|
-
require "active_support/core_ext/array/wrap"
|
7
|
-
require "active_support/core_ext/enumerable"
|
8
3
|
|
9
4
|
class Dorian
|
10
5
|
class Arguments
|
@@ -50,7 +45,7 @@ class Dorian
|
|
50
45
|
definition.each do |key, value|
|
51
46
|
type, default, aliases = normalize(value)
|
52
47
|
|
53
|
-
keys = ([key] + aliases).map(&:to_s).map(
|
48
|
+
keys = ([key] + aliases).map(&:to_s).map { |key| parameterize(key) }
|
54
49
|
keys = keys.map { |key| ["--#{key}", "-#{key}"] }.flatten
|
55
50
|
|
56
51
|
indexes = []
|
@@ -81,7 +76,7 @@ class Dorian
|
|
81
76
|
|
82
77
|
values = [default] if values.empty?
|
83
78
|
values = values.map { |value| cast(type, value) }
|
84
|
-
values = values.first unless
|
79
|
+
values = values.first unless many?(values)
|
85
80
|
options[key] = values
|
86
81
|
end
|
87
82
|
|
@@ -89,7 +84,11 @@ class Dorian
|
|
89
84
|
|
90
85
|
arguments -= files
|
91
86
|
|
92
|
-
|
87
|
+
options = Struct.new(*options.keys).new(*options.values)
|
88
|
+
|
89
|
+
Struct.new(:arguments, :options, :files, :help).new(
|
90
|
+
arguments, options, files, help
|
91
|
+
)
|
93
92
|
end
|
94
93
|
|
95
94
|
def cast(type, value)
|
@@ -117,7 +116,7 @@ class Dorian
|
|
117
116
|
keys_message =
|
118
117
|
([key] + aliases)
|
119
118
|
.map(&:to_s)
|
120
|
-
.map(
|
119
|
+
.map { |key| parameterize(key) }
|
121
120
|
.map { |key| key.size == 1 ? "-#{key}" : "--#{key}" }
|
122
121
|
.join("|")
|
123
122
|
|
@@ -128,12 +127,25 @@ class Dorian
|
|
128
127
|
message
|
129
128
|
end
|
130
129
|
|
130
|
+
def many?(array)
|
131
|
+
array.size > 1
|
132
|
+
end
|
133
|
+
|
134
|
+
def parameterize(string, separator: "-")
|
135
|
+
string
|
136
|
+
.to_s
|
137
|
+
.encode("ASCII", invalid: :replace, undef: :replace, replace: "")
|
138
|
+
.downcase
|
139
|
+
.gsub(/[^a-z0-9]+/, separator)
|
140
|
+
.gsub(/^#{separator}+|#{separator}+$/, "")
|
141
|
+
end
|
142
|
+
|
131
143
|
def normalize(value)
|
132
144
|
if value.is_a?(Hash)
|
133
145
|
type = value[:type]&.to_s || DEFAULT_TYPE
|
134
146
|
default = value[:default]&.to_s || DEFAULT
|
135
147
|
aliases =
|
136
|
-
Array
|
148
|
+
Array(
|
137
149
|
value[:alias]&.to_s || value[:aliases]&.map(&:to_s) ||
|
138
150
|
DEFAULT_ALIASES
|
139
151
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-arguments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
@@ -10,20 +10,6 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bigdecimal
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +24,6 @@ dependencies:
|
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: dorian-to_struct
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
27
|
description: parses arguments
|
56
28
|
email: dorian@dorianmarie.com
|
57
29
|
executables:
|