vv 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vv/array_methods.rb +1 -36
- data/lib/vv/cli.rb +50 -9
- data/lib/vv/file_methods.rb +1 -0
- data/lib/vv/gem_methods.rb +1 -0
- data/lib/vv/set_methods.rb +88 -0
- data/lib/vv/version.rb +1 -1
- data/lib/vv.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51e268d782cc4e4615a19f9bef609d810465b50bf74fa7161d9cb1ed02fa3caf
|
4
|
+
data.tar.gz: 3f2ce5fac2641daf1b82d38df2b0e682aec543bf14a8f485c1976acb5bc9a0ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85bab86083aa0ff67da2ba25e85fab3a8fb2edc7f430e477bdf2bacee7f95f4aa959eabb0cae117d8af0073e507fa446f8da4b121f3d27170c8fe0fb390c9cc7
|
7
|
+
data.tar.gz: 923ae7cbe0ff1166a5653597e58b18ec38bf42cd2ce0f6644553c1f27598d13670c7fce0b5a5008cf7053590756a5d39900e4fcef5ed2525e18d2719dc9008ae
|
data/lib/vv/array_methods.rb
CHANGED
@@ -3,6 +3,7 @@ module VV
|
|
3
3
|
|
4
4
|
def self.included(base)
|
5
5
|
base.extend(ClassMethods)
|
6
|
+
base.include(VV::SetMethods::SetAndArrayMethods)
|
6
7
|
base.attr_accessor :cli_print_separator
|
7
8
|
end
|
8
9
|
|
@@ -14,42 +15,6 @@ module VV
|
|
14
15
|
|
15
16
|
end
|
16
17
|
|
17
|
-
def gravify
|
18
|
-
self.collect do |elem|
|
19
|
-
"`#{elem}`"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def gravify!
|
24
|
-
self.collect! do |elem|
|
25
|
-
"`#{elem}`"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def includes_any?(other)
|
30
|
-
raise TypeError, "Expecting array" unless other.is_a? Array
|
31
|
-
uother = other.uniq
|
32
|
-
uself = self.uniq
|
33
|
-
(uself + uother).uniq.size < (uself.size + uother.size)
|
34
|
-
end
|
35
|
-
|
36
|
-
def include_any?(other)
|
37
|
-
self.includes_any?(other)
|
38
|
-
end
|
39
|
-
|
40
|
-
def stringify_collection grave: false
|
41
|
-
return self.gravify.stringify_collection if grave
|
42
|
-
|
43
|
-
return String.empty_string if self.blank?
|
44
|
-
return self.first if self.size == 1
|
45
|
-
return self.join " and " if self.size == 2
|
46
|
-
|
47
|
-
new_collection = self[0..-3]
|
48
|
-
back_fragment = self[-2..-1].join ", and "
|
49
|
-
new_collection << back_fragment
|
50
|
-
new_collection.join ", "
|
51
|
-
end
|
52
|
-
|
53
18
|
def spaced
|
54
19
|
self.join(" ")
|
55
20
|
end
|
data/lib/vv/cli.rb
CHANGED
@@ -6,10 +6,12 @@ module VV
|
|
6
6
|
:settings,
|
7
7
|
:cache_path,
|
8
8
|
:config_path,
|
9
|
-
:data_path
|
9
|
+
:data_path,
|
10
|
+
:verbosity
|
10
11
|
|
11
12
|
def initialize version: nil,
|
12
13
|
name: nil,
|
14
|
+
argv: nil,
|
13
15
|
config_path: nil,
|
14
16
|
cache_path: nil,
|
15
17
|
data_path: nil
|
@@ -28,6 +30,11 @@ module VV
|
|
28
30
|
@settings = nil
|
29
31
|
|
30
32
|
self.set_default_paths
|
33
|
+
|
34
|
+
# Most of the time we want to just initialize the
|
35
|
+
# thing fully, but it's helpful to test and debug if
|
36
|
+
# we're not forced to.
|
37
|
+
self.parse_flags argv unless argv.nil?
|
31
38
|
end
|
32
39
|
|
33
40
|
def set_default_paths
|
@@ -47,6 +54,38 @@ module VV
|
|
47
54
|
def parse_flags argv
|
48
55
|
argv = argv.split " " if argv.is_a? String
|
49
56
|
@settings = @option_router.parse argv
|
57
|
+
set_verbosity
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_normal_verbosity
|
61
|
+
@verbosity = :normal
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_verbosity
|
65
|
+
verbosity_flags = %w[ -v -vv -vvv -q -s ]
|
66
|
+
flag_set = @settings.keys.includes_any? verbosity_flags
|
67
|
+
return self.set_normal_verbosity unless flag_set
|
68
|
+
|
69
|
+
@settings.keys.includes_one! verbosity_flags
|
70
|
+
|
71
|
+
flag = (@settings.keys & verbosity_flags).first
|
72
|
+
|
73
|
+
|
74
|
+
index = verbosity_flags.index(flag)
|
75
|
+
@verbosity = %i[ verbose
|
76
|
+
very_verbose
|
77
|
+
very_very_verbose
|
78
|
+
quiet
|
79
|
+
absolute_silence ][index]
|
80
|
+
end
|
81
|
+
|
82
|
+
def help?
|
83
|
+
return false if @settings.nil?
|
84
|
+
@settings["-h"]
|
85
|
+
end
|
86
|
+
|
87
|
+
def print_help width: 80
|
88
|
+
option_router.help_doc.cli_print width: width
|
50
89
|
end
|
51
90
|
|
52
91
|
end
|
@@ -112,7 +151,7 @@ module VV
|
|
112
151
|
"Duplicate command line flag #{@flag} encountered."
|
113
152
|
|
114
153
|
@flag = lookup_canonical_flag @flag
|
115
|
-
fail message if @
|
154
|
+
fail message if @parsed_arguments.include? @flag
|
116
155
|
|
117
156
|
self.set_flag
|
118
157
|
end
|
@@ -129,13 +168,13 @@ module VV
|
|
129
168
|
value = @value
|
130
169
|
value &&= @value.to_d if decimal?
|
131
170
|
value ||= true
|
132
|
-
@
|
171
|
+
@parsed_arguments[@flag] = value
|
133
172
|
end
|
134
173
|
|
135
174
|
# This needs a refactor.
|
136
175
|
def parse argv
|
137
176
|
@flags_cease = false
|
138
|
-
@
|
177
|
+
@parsed_arguments = {}
|
139
178
|
|
140
179
|
argv.each do |arg|
|
141
180
|
next add_input_arg arg if @flags_cease
|
@@ -155,7 +194,9 @@ module VV
|
|
155
194
|
self.cease_flag_consideration
|
156
195
|
end
|
157
196
|
|
158
|
-
@
|
197
|
+
@flag = @value = @current_flag = nil
|
198
|
+
|
199
|
+
@parsed_arguments
|
159
200
|
end
|
160
201
|
|
161
202
|
def end_of_commands
|
@@ -250,8 +291,8 @@ module VV
|
|
250
291
|
collection = \
|
251
292
|
@flag_settings[@flag][:type] == :collection
|
252
293
|
if collection
|
253
|
-
@
|
254
|
-
@
|
294
|
+
@parsed_arguments[@flag] ||= []
|
295
|
+
@parsed_arguments[@flag] << @value
|
255
296
|
else
|
256
297
|
@current_flag = nil
|
257
298
|
self.set_flag
|
@@ -260,8 +301,8 @@ module VV
|
|
260
301
|
end
|
261
302
|
|
262
303
|
def add_input_arg arg
|
263
|
-
@
|
264
|
-
@
|
304
|
+
@parsed_arguments[:input_arguments] ||= []
|
305
|
+
@parsed_arguments[:input_arguments] << arg
|
265
306
|
end
|
266
307
|
|
267
308
|
def standardize_value
|
data/lib/vv/file_methods.rb
CHANGED
data/lib/vv/gem_methods.rb
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
module VV
|
2
|
+
|
3
|
+
module SetMethods
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
base.include(SetAndArrayMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def vv_included?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module SetAndArrayMethods
|
19
|
+
|
20
|
+
def gravify
|
21
|
+
self.collect do |elem|
|
22
|
+
"`#{elem}`"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def gravify!
|
27
|
+
self.collect! do |elem|
|
28
|
+
"`#{elem}`"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def includes! other
|
33
|
+
return if self.include? other
|
34
|
+
fail "Collection does not include `#{other}`."
|
35
|
+
end
|
36
|
+
alias_method :include!, :includes!
|
37
|
+
|
38
|
+
def includes_one?(other)
|
39
|
+
ok_type = other.is_a? Array
|
40
|
+
ok_type ||= other.is_a? Set
|
41
|
+
|
42
|
+
fail TypeError, "Expecting array" unless ok_type
|
43
|
+
|
44
|
+
( self & other ).one?
|
45
|
+
end
|
46
|
+
alias_method :include_one?, :includes_one?
|
47
|
+
|
48
|
+
def includes_one!(other)
|
49
|
+
return true if includes_one? other
|
50
|
+
message = "Collections did not share exactly one element."
|
51
|
+
fail message
|
52
|
+
end
|
53
|
+
alias_method :include_one!, :includes_one!
|
54
|
+
|
55
|
+
def includes_any?(other)
|
56
|
+
ok_type = other.is_a? Array
|
57
|
+
ok_type ||= other.is_a? Set
|
58
|
+
|
59
|
+
fail TypeError, "Expecting array" unless ok_type
|
60
|
+
( self & other ).any?
|
61
|
+
end
|
62
|
+
alias_method :include_any?, :includes_any?
|
63
|
+
|
64
|
+
def includes_any! other
|
65
|
+
return true if includes_any? other
|
66
|
+
message = "Collections did not share exactly any elements."
|
67
|
+
fail message
|
68
|
+
end
|
69
|
+
alias_method :include_any!, :includes_any!
|
70
|
+
|
71
|
+
def stringify_collection grave: false
|
72
|
+
return self.gravify.stringify_collection if grave
|
73
|
+
|
74
|
+
return String.empty_string if self.blank?
|
75
|
+
return self.first if self.size == 1
|
76
|
+
return self.join " and " if self.size == 2
|
77
|
+
|
78
|
+
new_collection = self[0..-3]
|
79
|
+
back_fragment = self[-2..-1].join ", and "
|
80
|
+
new_collection << back_fragment
|
81
|
+
new_collection.join ", "
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/lib/vv/version.rb
CHANGED
data/lib/vv.rb
CHANGED
@@ -5,6 +5,7 @@ require 'bigdecimal/util'
|
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
7
|
require_relative "vv/gem_methods"
|
8
|
+
require_relative "vv/set_methods"
|
8
9
|
|
9
10
|
Gem.require_files "vv/*.rb"
|
10
11
|
Gem.require_files "vv/style/*.rb"
|
@@ -26,6 +27,10 @@ class Hash
|
|
26
27
|
include VV::HashMethods
|
27
28
|
end
|
28
29
|
|
30
|
+
class Set
|
31
|
+
include VV::SetMethods
|
32
|
+
end
|
33
|
+
|
29
34
|
class Array
|
30
35
|
include VV::ArrayMethods
|
31
36
|
end
|
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.10
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/vv/object_methods.rb
|
74
74
|
- lib/vv/random_methods.rb
|
75
75
|
- lib/vv/readline_methods.rb
|
76
|
+
- lib/vv/set_methods.rb
|
76
77
|
- lib/vv/string_methods.rb
|
77
78
|
- lib/vv/style/bold.rb
|
78
79
|
- lib/vv/style/color.rb
|