samovar 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/samovar/command.rb +5 -0
- data/lib/samovar/flags.rb +70 -21
- data/lib/samovar/option.rb +3 -2
- data/lib/samovar/options.rb +4 -2
- data/lib/samovar/table.rb +4 -3
- data/lib/samovar/version.rb +1 -1
- data/license.md +1 -1
- data/readme.md +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -46
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e30e7064ff47b5ddb9d3461d291513e310fe7000d96abf00c473447d76c4f17
|
4
|
+
data.tar.gz: 3ec1e17b743863c3df573f959450922c9aec4fcedbf4fe8a690657effcc643f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16adeb378b0451726310d57f76b7223c37a51a43fbf21d1348c3d309b94ae1b99fb943736362c3c66f0b1c651630982f9a5eba5b32bfb8202c0704370e67a6cc
|
7
|
+
data.tar.gz: b9bbcfbdc77d330992c47eebfdb10c612d57f140ef0b6e8f97204e3d67d2ccf2f020313cdf54c816122cebb279c82a315db40820d60ef74f41de118c7f5d4873
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/samovar/command.rb
CHANGED
@@ -46,6 +46,11 @@ module Samovar
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.append(row)
|
49
|
+
if method_defined?(row.key, false)
|
50
|
+
warning "Method for key #{row.key} is already defined!", caller
|
51
|
+
# raise ArgumentError, "Method for key #{row.key} is already defined!"
|
52
|
+
end
|
53
|
+
|
49
54
|
attr_accessor(row.key) if row.respond_to?(:key)
|
50
55
|
|
51
56
|
self.table << row
|
data/lib/samovar/flags.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2016-
|
4
|
+
# Copyright, 2016-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
module Samovar
|
7
7
|
class Flags
|
8
8
|
def initialize(text)
|
9
9
|
@text = text
|
10
10
|
|
11
|
-
@ordered = text.split(/\s+\|\s+/).map{|part| Flag.
|
11
|
+
@ordered = text.split(/\s+\|\s+/).map{|part| Flag.parse(part)}
|
12
12
|
end
|
13
13
|
|
14
14
|
def each(&block)
|
@@ -21,7 +21,7 @@ module Samovar
|
|
21
21
|
|
22
22
|
# Whether or not this flag should have a true/false value if not specified otherwise.
|
23
23
|
def boolean?
|
24
|
-
@ordered.count == 1 and @ordered.first.
|
24
|
+
@ordered.count == 1 and @ordered.first.boolean?
|
25
25
|
end
|
26
26
|
|
27
27
|
def count
|
@@ -29,12 +29,13 @@ module Samovar
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_s
|
32
|
-
|
32
|
+
"[#{@ordered.join(' | ')}]"
|
33
33
|
end
|
34
34
|
|
35
35
|
def parse(input)
|
36
36
|
@ordered.each do |flag|
|
37
|
-
|
37
|
+
result = flag.parse(input)
|
38
|
+
if result != nil
|
38
39
|
return result
|
39
40
|
end
|
40
41
|
end
|
@@ -44,45 +45,93 @@ module Samovar
|
|
44
45
|
end
|
45
46
|
|
46
47
|
class Flag
|
47
|
-
def
|
48
|
-
@text = text
|
49
|
-
|
48
|
+
def self.parse(text)
|
50
49
|
if text =~ /(.*?)\s(\<.*?\>)/
|
51
|
-
|
52
|
-
|
50
|
+
ValueFlag.new(text, $1, $2)
|
51
|
+
elsif text =~ /--\[no\]-(.*?)$/
|
52
|
+
BooleanFlag.new(text, "--#{$1}")
|
53
53
|
else
|
54
|
-
|
55
|
-
@value = nil
|
54
|
+
ValueFlag.new(text, text, nil)
|
56
55
|
end
|
57
|
-
|
58
|
-
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize(text, prefix, alternatives = nil)
|
59
|
+
@text = text
|
60
|
+
@prefix = prefix
|
61
|
+
@alternatives = alternatives
|
59
62
|
end
|
60
63
|
|
61
64
|
attr :text
|
62
65
|
attr :prefix
|
63
66
|
attr :alternatives
|
64
|
-
attr :value
|
65
67
|
|
66
68
|
def to_s
|
67
69
|
@text
|
68
70
|
end
|
69
71
|
|
70
|
-
def prefix?(token)
|
71
|
-
@prefix == token or @alternatives.include?(token)
|
72
|
-
end
|
73
|
-
|
74
72
|
def key
|
75
73
|
@key ||= @prefix.sub(/^-*/, '').gsub('-', '_').to_sym
|
76
74
|
end
|
77
75
|
|
76
|
+
def boolean?
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class ValueFlag < Flag
|
82
|
+
def initialize(text, prefix, value)
|
83
|
+
super(text, prefix)
|
84
|
+
|
85
|
+
@value = value
|
86
|
+
|
87
|
+
*@alternatives, @prefix = @prefix.split('/')
|
88
|
+
end
|
89
|
+
|
90
|
+
attr :alternatives
|
91
|
+
attr :value
|
92
|
+
|
93
|
+
def boolean?
|
94
|
+
@value.nil?
|
95
|
+
end
|
96
|
+
|
97
|
+
def prefix?(token)
|
98
|
+
@prefix == token or @alternatives.include?(token)
|
99
|
+
end
|
100
|
+
|
78
101
|
def parse(input)
|
79
102
|
if prefix?(input.first)
|
80
103
|
if @value
|
81
|
-
input.shift(2).last
|
104
|
+
return input.shift(2).last
|
82
105
|
else
|
83
|
-
input.shift
|
106
|
+
input.shift
|
107
|
+
return key
|
84
108
|
end
|
85
109
|
end
|
86
110
|
end
|
87
111
|
end
|
112
|
+
|
113
|
+
class BooleanFlag < Flag
|
114
|
+
def initialize(text, prefix, value = nil)
|
115
|
+
super(text, prefix)
|
116
|
+
|
117
|
+
@value = value
|
118
|
+
|
119
|
+
@negated = @prefix.sub(/^--/, '--no-')
|
120
|
+
@alternatives = [@negated]
|
121
|
+
end
|
122
|
+
|
123
|
+
def prefix?(token)
|
124
|
+
@prefix == token or @negated == token
|
125
|
+
end
|
126
|
+
|
127
|
+
def parse(input)
|
128
|
+
if input.first == @prefix
|
129
|
+
input.shift
|
130
|
+
return true
|
131
|
+
elsif input.first == @negated
|
132
|
+
input.shift
|
133
|
+
return false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
88
137
|
end
|
data/lib/samovar/option.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative 'flags'
|
7
7
|
|
@@ -66,7 +66,8 @@ module Samovar
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def parse(input, parent = nil, default = nil)
|
69
|
-
|
69
|
+
result = @flags.parse(input)
|
70
|
+
if result != nil
|
70
71
|
@value.nil? ? coerce(result) : @value
|
71
72
|
elsif default ||= @default
|
72
73
|
return default
|
data/lib/samovar/options.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2016-
|
4
|
+
# Copyright, 2016-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative 'option'
|
7
7
|
|
@@ -90,7 +90,9 @@ module Samovar
|
|
90
90
|
values = (default || @defaults).dup
|
91
91
|
|
92
92
|
while option = @keyed[input.first]
|
93
|
-
|
93
|
+
prefix = input.first
|
94
|
+
result = option.parse(input)
|
95
|
+
if result != nil
|
94
96
|
values[option.key] = result
|
95
97
|
end
|
96
98
|
end
|
data/lib/samovar/table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2016-
|
4
|
+
# Copyright, 2016-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
module Samovar
|
7
7
|
class Table
|
@@ -76,8 +76,9 @@ module Samovar
|
|
76
76
|
|
77
77
|
current = parent.send(key)
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
result = row.parse(input, parent, current)
|
80
|
+
if result != nil
|
81
|
+
parent.public_send("#{row.key}=", result)
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
data/lib/samovar/version.rb
CHANGED
data/license.md
CHANGED
data/readme.md
CHANGED
@@ -188,7 +188,7 @@ This project uses the [Developer Certificate of Origin](https://developercertifi
|
|
188
188
|
|
189
189
|
### Contributor Covenant
|
190
190
|
|
191
|
-
This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
|
191
|
+
This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
|
192
192
|
|
193
193
|
## Future Work
|
194
194
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samovar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -38,7 +38,7 @@ cert_chain:
|
|
38
38
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
39
39
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
40
40
|
-----END CERTIFICATE-----
|
41
|
-
date:
|
41
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
42
42
|
dependencies:
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: console
|
@@ -68,48 +68,6 @@ dependencies:
|
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '1.0'
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: bundler
|
73
|
-
requirement: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
type: :development
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '0'
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: covered
|
87
|
-
requirement: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
92
|
-
type: :development
|
93
|
-
prerelease: false
|
94
|
-
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - ">="
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: '0'
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
name: sus
|
101
|
-
requirement: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
106
|
-
type: :development
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
113
71
|
description:
|
114
72
|
email:
|
115
73
|
executables: []
|
@@ -150,14 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
108
|
requirements:
|
151
109
|
- - ">="
|
152
110
|
- !ruby/object:Gem::Version
|
153
|
-
version: '0'
|
111
|
+
version: '3.0'
|
154
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
113
|
requirements:
|
156
114
|
- - ">="
|
157
115
|
- !ruby/object:Gem::Version
|
158
116
|
version: '0'
|
159
117
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.5.3
|
161
119
|
signing_key:
|
162
120
|
specification_version: 4
|
163
121
|
summary: Samovar is a flexible option parser excellent support for sub-commands and
|
metadata.gz.sig
CHANGED
Binary file
|