vv 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vv/cli.rb +43 -0
- data/lib/vv/object_methods.rb +7 -0
- data/lib/vv/readline_methods.rb +1 -0
- data/lib/vv/string_methods.rb +43 -0
- data/lib/vv/utility/lookup_table.rb +37 -19
- data/lib/vv/version.rb +1 -1
- data/lib/vv.rb +6 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2d912eb9fcb0485c2139ebe4518ae370ce45125c86d5bb626b3beb056068a7c
|
4
|
+
data.tar.gz: c0c9004e1998216defa6efc4a7568ef397920bc35754c43f23a6279be596dbf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65d5efbd8f5b7e2e9da027954375920164b2e0b246b95edeb3b381a139b30d4e76570f77b0fa43c9c45dd55542fabacbd5bd996beb832a8c344fcca0b2740606
|
7
|
+
data.tar.gz: 31b97ec5a249b43d8419debf89cb59e48fa6c4786684be18eae8d61b9f8c6d4bd5e4dffe1af2617ce22b20d4aae202edff0acbf4110598627f418b764dabbb45
|
data/lib/vv/cli.rb
CHANGED
@@ -79,15 +79,58 @@ module VV
|
|
79
79
|
absolute_silence ][index]
|
80
80
|
end
|
81
81
|
|
82
|
+
def await_input message: nil,
|
83
|
+
force_match: false,
|
84
|
+
input: nil
|
85
|
+
|
86
|
+
input = input
|
87
|
+
input ||= Readline.prompt message
|
88
|
+
|
89
|
+
@prompt_message = message.unstyled
|
90
|
+
@prompt_message ||= ""
|
91
|
+
|
92
|
+
response = self.parse_message! input: input
|
93
|
+
|
94
|
+
@prompt_message = nil
|
95
|
+
|
96
|
+
response
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse_message! input:
|
100
|
+
@prompt_table = LookupTable.new ignore_case: true
|
101
|
+
options = @prompt_message.split(String.colon).last
|
102
|
+
tokens = options.split_english
|
103
|
+
|
104
|
+
tokens.each do |_token|
|
105
|
+
token = _token.gsub("(","").gsub(")","")
|
106
|
+
alias_token = _token.split("(")[-1].split(")")[0]
|
107
|
+
@prompt_table[token] = true
|
108
|
+
@prompt_table.alias key: alias_token, to: token
|
109
|
+
end
|
110
|
+
|
111
|
+
response = @prompt_table.lookup_key input
|
112
|
+
|
113
|
+
response || input
|
114
|
+
end
|
115
|
+
|
82
116
|
def help?
|
83
117
|
return false if @settings.nil?
|
84
118
|
@settings["-h"]
|
85
119
|
end
|
86
120
|
|
121
|
+
def version?
|
122
|
+
return false if @settings.nil?
|
123
|
+
@settings["-V"]
|
124
|
+
end
|
125
|
+
|
87
126
|
def print_help width: 80
|
88
127
|
option_router.help_doc.cli_print width: width
|
89
128
|
end
|
90
129
|
|
130
|
+
def print_version width: 80
|
131
|
+
"#{self.name} version #{@version}".cli_puts
|
132
|
+
end
|
133
|
+
|
91
134
|
end
|
92
135
|
|
93
136
|
class OptionRouter
|
data/lib/vv/object_methods.rb
CHANGED
data/lib/vv/readline_methods.rb
CHANGED
data/lib/vv/string_methods.rb
CHANGED
@@ -130,6 +130,45 @@ module VV
|
|
130
130
|
self.with_ending newline
|
131
131
|
end
|
132
132
|
|
133
|
+
def split_via *arguments, ignore_newlines: false
|
134
|
+
newlines_encountered = self.include? String.newline
|
135
|
+
newlines_ok = ( not newlines_encountered )
|
136
|
+
newlines_ok ||= ignore_newlines
|
137
|
+
|
138
|
+
message = "Newlines encountered, but disallowed. "
|
139
|
+
message += \
|
140
|
+
"Set `ignore_newlines` to true to treat as spaces."
|
141
|
+
|
142
|
+
fail message unless newlines_ok
|
143
|
+
|
144
|
+
args = arguments.flatten.sort_by(&:length).reverse
|
145
|
+
|
146
|
+
response = [self.gsub(String.newline, String.space)]
|
147
|
+
|
148
|
+
args.map do |arg|
|
149
|
+
|
150
|
+
response.map! do |fragment|
|
151
|
+
fragment.split arg
|
152
|
+
end
|
153
|
+
|
154
|
+
response.flatten!
|
155
|
+
end
|
156
|
+
|
157
|
+
response
|
158
|
+
end
|
159
|
+
|
160
|
+
def split_english ignore_newlines: false
|
161
|
+
|
162
|
+
options = [ ", ",
|
163
|
+
", and ",
|
164
|
+
", or ",
|
165
|
+
" and ",
|
166
|
+
" or "]
|
167
|
+
self.split_via(options,
|
168
|
+
ignore_newlines: ignore_newlines)
|
169
|
+
.map(&:strip)
|
170
|
+
end
|
171
|
+
|
133
172
|
def squish!
|
134
173
|
self.gsub!(/\A[[:space:]]+/, "")
|
135
174
|
self.gsub!(/[[:space:]]+\z/, "")
|
@@ -465,6 +504,10 @@ module VV
|
|
465
504
|
self[9]
|
466
505
|
end
|
467
506
|
|
507
|
+
def cli_puts **kwargs
|
508
|
+
puts String.get_stdout { self.cli_print( **kwargs ) }
|
509
|
+
end
|
510
|
+
|
468
511
|
def cli_print width: 80,
|
469
512
|
padding: 0,
|
470
513
|
position: 0,
|
@@ -1,14 +1,26 @@
|
|
1
1
|
class LookupTable
|
2
2
|
|
3
|
-
attr_reader :canonnicals,
|
3
|
+
attr_reader :canonnicals,
|
4
|
+
:aliases,
|
5
|
+
:data,
|
6
|
+
:ignore_case
|
4
7
|
|
5
|
-
def initialize
|
8
|
+
def initialize ignore_case: false
|
9
|
+
@ignore_case = ignore_case
|
6
10
|
@canonicals = Hash.new
|
7
11
|
@aliases = Hash.new
|
8
12
|
@data = Hash.new
|
9
13
|
end
|
10
14
|
|
11
15
|
def alias( key:, to: )
|
16
|
+
|
17
|
+
if @ignore_case
|
18
|
+
key = key.downcase
|
19
|
+
to = to.downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
return if key == to
|
23
|
+
|
12
24
|
_ensure_alias_possible key
|
13
25
|
|
14
26
|
@canonicals[key] = to
|
@@ -18,14 +30,17 @@ class LookupTable
|
|
18
30
|
end
|
19
31
|
|
20
32
|
def []= key, value
|
33
|
+
key = key.downcase if @ignore_case
|
21
34
|
@data[ self.canonical key ] = value
|
22
35
|
end
|
23
36
|
|
24
37
|
def [] key
|
38
|
+
key = key.downcase if @ignore_case
|
25
39
|
@data[ self.canonical key ]
|
26
40
|
end
|
27
41
|
|
28
42
|
def canonical key
|
43
|
+
key = key.downcase if @ignore_case
|
29
44
|
@canonicals[key] || key
|
30
45
|
end
|
31
46
|
|
@@ -34,6 +49,7 @@ class LookupTable
|
|
34
49
|
end
|
35
50
|
|
36
51
|
def include? key
|
52
|
+
key = key.downcase if @ignore_case
|
37
53
|
@data.include?( self.canonical key )
|
38
54
|
end
|
39
55
|
|
@@ -48,30 +64,32 @@ class LookupTable
|
|
48
64
|
}
|
49
65
|
end
|
50
66
|
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
return self.to_h.public_send method, **kwargs, &block
|
62
|
-
else
|
63
|
-
return self.to_h.public_send method, &block
|
64
|
-
end
|
65
|
-
rescue NoMethodError
|
66
|
-
end
|
67
|
-
raise
|
67
|
+
# Because case is ignorable we can't automatically
|
68
|
+
# delegate all methods, only those without arguments
|
69
|
+
def keys *args, **kwargs, &block
|
70
|
+
both = args.present? && kwargs.present?
|
71
|
+
|
72
|
+
return to_h.keys(*args, **kwargs, &block) if both
|
73
|
+
return to_h.keys(**kwargs, &block) if kwargs.present?
|
74
|
+
return to_h.keys(*args, &block) if args.present?
|
75
|
+
|
76
|
+
to_h.keys( &block )
|
68
77
|
end
|
69
78
|
|
70
79
|
def lookup_canonical key
|
80
|
+
key = key.downcase if @ignore_case
|
81
|
+
|
71
82
|
return key if self.canonical_keys.include? key
|
72
83
|
|
73
84
|
@canonicals[key]
|
74
85
|
end
|
86
|
+
alias_method :lookup_key, :lookup_canonical
|
87
|
+
|
88
|
+
def fuzzy_lookup_canonical key
|
89
|
+
raise NotImplementedError
|
90
|
+
key = key.downcase if @ignore_case
|
91
|
+
Dir.glob pattern
|
92
|
+
end
|
75
93
|
|
76
94
|
protected
|
77
95
|
|
data/lib/vv/version.rb
CHANGED
data/lib/vv.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "securerandom"
|
2
|
+
require "readline"
|
3
|
+
require "set"
|
4
|
+
require "bigdecimal"
|
5
|
+
require "bigdecimal/util"
|
6
|
+
require "fileutils"
|
6
7
|
|
7
8
|
require_relative "vv/gem_methods"
|
8
9
|
require_relative "vv/set_methods"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Aysan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|