everyday-cli-utils 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.ci +1 -3
- data/everyday-cli-utils.gemspec +0 -2
- data/lib/everyday-cli-utils/version.rb +1 -1
- data/spec/everyday-cli-utils/format_spec.rb +33 -33
- data/spec/everyday-cli-utils/kmeans_spec.rb +5 -5
- data/spec/everyday-cli-utils/maputil_spec.rb +15 -15
- data/spec/everyday-cli-utils/option_spec.rb +70 -70
- data/spec/everyday-cli-utils/override_spec.rb +5 -5
- data/spec/spec_helper.rb +0 -2
- metadata +3 -33
- data/.coveralls.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b782f421cdd9590afee254f31a04ede52ea639
|
4
|
+
data.tar.gz: 15cc9c8b271b27098d55d9a200c1108b8be17a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b018a8acffbbb70a677bcc064eadfa03291bfe8ffae3e70aa1404ec68e362d25e9136f2b9f9317c8893120d7ad74c0b09ab2777b7cc809ddfb7418c1d0f13e
|
7
|
+
data.tar.gz: 353c6a1b8d6ee9be21ee2335a6bc82c801bbdd24f9313be231cccd6cfea9945aa94c97866779eb14b9cc5eddd02c9b7b0ac815ae0581e80cbc2c8a48b977e8d4
|
data/Gemfile.ci
CHANGED
data/everyday-cli-utils.gemspec
CHANGED
@@ -22,7 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
-
spec.add_development_dependency 'simplecov', '>= 0.8.2'
|
26
|
-
spec.add_development_dependency 'coveralls', '>= 0.7.0'
|
27
25
|
spec.add_development_dependency 'rspec'
|
28
26
|
end
|
@@ -10,15 +10,15 @@ end
|
|
10
10
|
describe EverydayCliUtils::Format do
|
11
11
|
it 'adds formatting methods to String' do
|
12
12
|
str = 'hi'
|
13
|
-
str.respond_to?(:format_bold_underline_fg_yellow_bg_green).
|
14
|
-
str.respond_to?(:format_underline_bg_green).
|
13
|
+
expect(str.respond_to?(:format_bold_underline_fg_yellow_bg_green)).to be true
|
14
|
+
expect(str.respond_to?(:format_underline_bg_green)).to be true
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'does the same formatting in the String methods and the Format methods' do
|
18
18
|
str = 'hi'
|
19
19
|
format_str = EverydayCliUtils::Format.boldunderline(str, :yellow, :green)
|
20
20
|
string_str = str.format_bold_underline_fg_yellow_bg_green
|
21
|
-
format_str.
|
21
|
+
expect(format_str).to eq string_str
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'can parse a format it creates' do
|
@@ -26,47 +26,47 @@ describe EverydayCliUtils::Format do
|
|
26
26
|
format_str = EverydayCliUtils::Format.bold(str, :yellow, :green)
|
27
27
|
piece = extract_format(format_str)
|
28
28
|
bold, underline, fgcolor, bgcolor = EverydayCliUtils::Format.parse_format(piece)
|
29
|
-
bold.
|
30
|
-
underline.
|
31
|
-
fgcolor.
|
32
|
-
bgcolor.
|
29
|
+
expect(bold).to be true
|
30
|
+
expect(underline).to be false
|
31
|
+
expect(fgcolor).to eq :yellow
|
32
|
+
expect(bgcolor).to eq :green
|
33
33
|
|
34
34
|
format_str = EverydayCliUtils::Format.underline(str, :yellow, :green)
|
35
35
|
piece = extract_format(format_str)
|
36
36
|
bold, underline, fgcolor, bgcolor = EverydayCliUtils::Format.parse_format(piece)
|
37
|
-
bold.
|
38
|
-
underline.
|
39
|
-
fgcolor.
|
40
|
-
bgcolor.
|
37
|
+
expect(bold).to be false
|
38
|
+
expect(underline).to be true
|
39
|
+
expect(fgcolor).to eq :yellow
|
40
|
+
expect(bgcolor).to eq :green
|
41
41
|
|
42
42
|
format_str = EverydayCliUtils::Format.colorize(str, :yellow, :green)
|
43
43
|
piece = extract_format(format_str)
|
44
44
|
bold, underline, fgcolor, bgcolor = EverydayCliUtils::Format.parse_format(piece)
|
45
|
-
bold.
|
46
|
-
underline.
|
47
|
-
fgcolor.
|
48
|
-
bgcolor.
|
45
|
+
expect(bold).to be false
|
46
|
+
expect(underline).to be false
|
47
|
+
expect(fgcolor).to eq :yellow
|
48
|
+
expect(bgcolor).to eq :green
|
49
49
|
|
50
50
|
format_str = EverydayCliUtils::Format.boldunderline(str, :yellow, :green)
|
51
51
|
piece = extract_format(format_str)
|
52
52
|
bold, underline, fgcolor, bgcolor = EverydayCliUtils::Format.parse_format(piece)
|
53
|
-
bold.
|
54
|
-
underline.
|
55
|
-
fgcolor.
|
56
|
-
bgcolor.
|
53
|
+
expect(bold).to be true
|
54
|
+
expect(underline).to be true
|
55
|
+
expect(fgcolor).to eq :yellow
|
56
|
+
expect(bgcolor).to eq :green
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'still works with the default String method_missing and respond_to?' do
|
60
60
|
str = 'hi'
|
61
|
-
str.respond_to?(:split).
|
62
|
-
str.respond_to?(:hi).
|
61
|
+
expect(str.respond_to?(:split)).to be true
|
62
|
+
expect(str.respond_to?(:hi)).to be false
|
63
63
|
expect { str.hi }.to raise_error(NameError)
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'allows shorthand for formatting in-string' do
|
67
67
|
str = 'abc {def}(bdulfywbgr) ghi {jkl}(ulfyw) mno'
|
68
68
|
expected = "abc #{'def'.format_bold_underline_fg_yellow_bg_green} ghi #{'jkl'.format_underline_fg_yellow} mno"
|
69
|
-
str.format_all.
|
69
|
+
expect(str.format_all).to eq expected
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'allows color profiles for use in shorthand for formatting in-string' do
|
@@ -74,13 +74,13 @@ describe EverydayCliUtils::Format do
|
|
74
74
|
EverydayCliUtils::Format.color_profile(:p2, underline: true, fgcolor: :yellow)
|
75
75
|
str = 'abc {def}(:p1) ghi {jkl}(:p2) mno'
|
76
76
|
expected = "abc #{'def'.format_bold_underline_fg_yellow_bg_green} ghi #{'jkl'.format_underline_fg_yellow} mno"
|
77
|
-
str.format_all.
|
77
|
+
expect(str.format_all).to eq expected
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'allows removing shorthand for formatting in-string' do
|
81
81
|
str = 'abc {def}(bdulfywbgr) ghi {jkl}(ulfyw) mno'
|
82
82
|
expected = 'abc def ghi jkl mno'
|
83
|
-
str.remove_format.
|
83
|
+
expect(str.remove_format).to eq expected
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'allows removing color profile shorthand for formatting in-string' do
|
@@ -88,7 +88,7 @@ describe EverydayCliUtils::Format do
|
|
88
88
|
EverydayCliUtils::Format.color_profile(:p2, underline: true, fgcolor: :yellow)
|
89
89
|
str = 'abc {def}(:p1) ghi {jkl}(:p2) mno'
|
90
90
|
expected = 'abc def ghi jkl mno'
|
91
|
-
str.remove_format.
|
91
|
+
expect(str.remove_format).to eq expected
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'allows centering a formatted string' do
|
@@ -100,8 +100,8 @@ describe EverydayCliUtils::Format do
|
|
100
100
|
trailing_whitespace = str2.length - str2.rstrip.length
|
101
101
|
leading_whitespace_f = strf2.length - strf2.lstrip.length
|
102
102
|
trailing_whitespace_f = strf2.length - strf2.rstrip.length
|
103
|
-
leading_whitespace_f.
|
104
|
-
trailing_whitespace_f.
|
103
|
+
expect(leading_whitespace_f).to eq leading_whitespace
|
104
|
+
expect(trailing_whitespace_f).to eq trailing_whitespace
|
105
105
|
|
106
106
|
str = 'abcd'
|
107
107
|
str2 = str.center(10)
|
@@ -111,8 +111,8 @@ describe EverydayCliUtils::Format do
|
|
111
111
|
trailing_whitespace = str2.length - str2.rstrip.length
|
112
112
|
leading_whitespace_f = strf2.length - strf2.lstrip.length
|
113
113
|
trailing_whitespace_f = strf2.length - strf2.rstrip.length
|
114
|
-
leading_whitespace_f.
|
115
|
-
trailing_whitespace_f.
|
114
|
+
expect(leading_whitespace_f).to eq leading_whitespace
|
115
|
+
expect(trailing_whitespace_f).to eq trailing_whitespace
|
116
116
|
|
117
117
|
str = 'abc'
|
118
118
|
str2 = str.center(11)
|
@@ -122,8 +122,8 @@ describe EverydayCliUtils::Format do
|
|
122
122
|
trailing_whitespace = str2.length - str2.rstrip.length
|
123
123
|
leading_whitespace_f = strf2.length - strf2.lstrip.length
|
124
124
|
trailing_whitespace_f = strf2.length - strf2.rstrip.length
|
125
|
-
leading_whitespace_f.
|
126
|
-
trailing_whitespace_f.
|
125
|
+
expect(leading_whitespace_f).to eq leading_whitespace
|
126
|
+
expect(trailing_whitespace_f).to eq trailing_whitespace
|
127
127
|
|
128
128
|
str = 'abcd'
|
129
129
|
str2 = str.center(11)
|
@@ -133,7 +133,7 @@ describe EverydayCliUtils::Format do
|
|
133
133
|
trailing_whitespace = str2.length - str2.rstrip.length
|
134
134
|
leading_whitespace_f = strf2.length - strf2.lstrip.length
|
135
135
|
trailing_whitespace_f = strf2.length - strf2.rstrip.length
|
136
|
-
leading_whitespace_f.
|
137
|
-
trailing_whitespace_f.
|
136
|
+
expect(leading_whitespace_f).to eq leading_whitespace
|
137
|
+
expect(trailing_whitespace_f).to eq trailing_whitespace
|
138
138
|
end
|
139
139
|
end
|
@@ -6,21 +6,21 @@ describe EverydayCliUtils::Kmeans do
|
|
6
6
|
it 'finds the right clusters in simple data' do
|
7
7
|
arr = [100, 200, 99, 400, 98, 201, 101, 405, 102]
|
8
8
|
nmeans = arr.nmeans
|
9
|
-
nmeans.count.
|
10
|
-
nmeans.
|
9
|
+
expect(nmeans.count).to eq 3
|
10
|
+
expect(nmeans).to eq [100, 200.5, 402.5]
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'limits number of clusters found' do
|
14
14
|
arr = (1..50).to_a.map { |v| (v * (101-v)) ** 2 }
|
15
15
|
nmeans = arr.nmeans(5)
|
16
|
-
nmeans.count.
|
16
|
+
expect(nmeans.count).to eq 5
|
17
17
|
nmeans = arr.nmeans(3)
|
18
|
-
nmeans.count.
|
18
|
+
expect(nmeans.count).to eq 3
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'finds outliers in simple data' do
|
22
22
|
arr = [100, 200, 99, 400, 98, 201, 101, 405, 102]
|
23
23
|
outliers = arr.outliers
|
24
|
-
outliers.
|
24
|
+
expect(outliers).to eq [400.0, 405.0]
|
25
25
|
end
|
26
26
|
end
|
@@ -5,81 +5,81 @@ import :maputil
|
|
5
5
|
describe 'maputil' do
|
6
6
|
it 'provides a shortcut for removing false values from a list' do
|
7
7
|
arr = [0, false, false, 3, 4, false, 6, false, 8, 9]
|
8
|
-
arr.removefalse.
|
8
|
+
expect(arr.removefalse).to eq [0, 3, 4, 6, 8, 9]
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'allows a filtered mapping' do
|
12
12
|
arr = (0..9).to_a
|
13
13
|
arr2 = arr.filtermap { |v| v % 3 == 0 ? false : v ** 2 }
|
14
|
-
arr2.
|
14
|
+
expect(arr2).to eq [1, 4, 16, 25, 49, 64]
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'provides a shortcut for summing the values of an list' do
|
18
18
|
arr = (0..9).to_a
|
19
19
|
sum = arr.sum
|
20
|
-
sum.
|
20
|
+
expect(sum).to eq 45
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'provides a shortcut for calculating the product of the values of an list' do
|
24
24
|
arr = (1..4).to_a
|
25
25
|
prod = arr.prod
|
26
|
-
prod.
|
26
|
+
expect(prod).to eq 24
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'provides a shortcut for calculating the average of the values of an list' do
|
30
30
|
arr = (0..9).to_a
|
31
31
|
avg = arr.floats.average
|
32
|
-
avg.
|
32
|
+
expect(avg).to eq 4.5
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'provides a shortcut for calculating the standard deviation of the values of an list' do
|
36
36
|
arr = (0..9).to_a.floats
|
37
37
|
std_dev = arr.std_dev
|
38
|
-
std_dev.
|
38
|
+
expect(std_dev).to eq Math.sqrt(8.25)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'provides a shortcut for calculating the sum of a mapped list' do
|
42
42
|
arr = (0..9).to_a
|
43
43
|
summap = arr.summap { |v| v ** 2 }
|
44
|
-
summap.
|
44
|
+
expect(summap).to eq 285
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'provides a shortcut for calculating the product of a mapped list' do
|
48
48
|
arr = (1..4).to_a
|
49
49
|
prodmap = arr.productmap { |v| v + 1 }
|
50
|
-
prodmap.
|
50
|
+
expect(prodmap).to eq 120
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'provides a shortcut to remove newlines from all strings in a list' do
|
54
54
|
arr = (0..9).to_a.map { |v| "#{v}\n" }
|
55
|
-
arr.
|
56
|
-
arr.chompall.
|
55
|
+
expect(arr).to eq %W(0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n)
|
56
|
+
expect(arr.chompall).to eq %w(0 1 2 3 4 5 6 7 8 9)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'provides a shortcut to join elements in a list' do
|
60
60
|
list = ('a'..'f')
|
61
61
|
joined = list.join('-')
|
62
|
-
joined.
|
62
|
+
expect(joined).to eq 'a-b-c-d-e-f'
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'provides a shortcut for making hashes with multiple keys that have the same value' do
|
66
66
|
hash = { [:a, :b, :c, :d] => '1-4', :e => '5' }
|
67
67
|
expanded = hash.expand
|
68
68
|
expected = { a: '1-4', b: '1-4', c: '1-4', d: '1-4', :e => '5' }
|
69
|
-
expanded.
|
69
|
+
expect(expanded).to eq expected
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'provides a means of cloning a hash' do
|
73
73
|
hash = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
74
74
|
cloned = hash.clone
|
75
|
-
hash.
|
75
|
+
expect(hash).to_not equal cloned
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'provides a means of using map with a hash' do
|
79
79
|
hash = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
|
80
80
|
mapped = hash.hashmap { |v| v[1] + ((v[0] == :a || v[0] == :c || v[0] == :e) ? 1 : -1) }
|
81
81
|
expected = { a: 2, b: 1, c: 4, d: 3, e: 6, f: 5}
|
82
|
-
mapped.
|
82
|
+
expect(mapped).to eq expected
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'provides a means of extending one hash with another' do
|
@@ -87,6 +87,6 @@ describe 'maputil' do
|
|
87
87
|
hash2 = { a: 11, d: 14, f: 16 }
|
88
88
|
extended = hash2.extend_hash(hash1)
|
89
89
|
expected = { a: 11, b: 2, c: 3, d: 14, e: 5, f: 16 }
|
90
|
-
extended.
|
90
|
+
expect(extended).to eq expected
|
91
91
|
end
|
92
92
|
end
|
@@ -12,15 +12,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
12
12
|
clean = { opt1: false }
|
13
13
|
opt = Option1.new
|
14
14
|
opt.option :opt1, %w(-1 --opt-1)
|
15
|
-
opt.options.
|
15
|
+
expect(opt.options).to eq clean
|
16
16
|
opt.default_options opt1: false
|
17
|
-
opt.options.
|
17
|
+
expect(opt.options).to eq clean
|
18
18
|
opt.parse!(['-1'])
|
19
|
-
opt.options.
|
19
|
+
expect(opt.options).to eq expected
|
20
20
|
opt.default_options opt1: false
|
21
|
-
opt.options.
|
21
|
+
expect(opt.options).to eq clean
|
22
22
|
opt.parse!(['--opt-1'])
|
23
|
-
opt.options.
|
23
|
+
expect(opt.options).to eq expected
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'supports adding boolean toggle options' do
|
@@ -28,15 +28,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
28
28
|
clean = { opt1: true }
|
29
29
|
opt = Option1.new
|
30
30
|
opt.option :opt1, %w(-1 --opt-1), toggle: true
|
31
|
-
opt.options.
|
31
|
+
expect(opt.options).to eq expected
|
32
32
|
opt.default_options opt1: true
|
33
|
-
opt.options.
|
33
|
+
expect(opt.options).to eq clean
|
34
34
|
opt.parse!(['-1'])
|
35
|
-
opt.options.
|
35
|
+
expect(opt.options).to eq expected
|
36
36
|
opt.default_options opt1: true
|
37
|
-
opt.options.
|
37
|
+
expect(opt.options).to eq clean
|
38
38
|
opt.parse!(['--opt-1'])
|
39
|
-
opt.options.
|
39
|
+
expect(opt.options).to eq expected
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'supports adding an option with a parameter' do
|
@@ -44,15 +44,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
44
44
|
clean = { opt1: nil }
|
45
45
|
opt = Option1.new
|
46
46
|
opt.option_with_param :opt1, ['-1', '--opt-1 PARAM']
|
47
|
-
opt.options.
|
47
|
+
expect(opt.options).to eq clean
|
48
48
|
opt.default_options opt1: nil
|
49
|
-
opt.options.
|
49
|
+
expect(opt.options).to eq clean
|
50
50
|
opt.parse!(%w(-1 hi))
|
51
|
-
opt.options.
|
51
|
+
expect(opt.options).to eq expected
|
52
52
|
opt.default_options opt1: nil
|
53
|
-
opt.options.
|
53
|
+
expect(opt.options).to eq clean
|
54
54
|
opt.parse!(%w(--opt-1 hi))
|
55
|
-
opt.options.
|
55
|
+
expect(opt.options).to eq expected
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'adds the parameter into a name if it is missing from all' do
|
@@ -60,15 +60,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
60
60
|
clean = { opt1: nil }
|
61
61
|
opt = Option1.new
|
62
62
|
opt.option_with_param :opt1, %w(-1 --opt-1)
|
63
|
-
opt.options.
|
63
|
+
expect(opt.options).to eq clean
|
64
64
|
opt.default_options opt1: nil
|
65
|
-
opt.options.
|
65
|
+
expect(opt.options).to eq clean
|
66
66
|
opt.parse!(%w(-1 hi))
|
67
|
-
opt.options.
|
67
|
+
expect(opt.options).to eq expected
|
68
68
|
opt.default_options opt1: nil
|
69
|
-
opt.options.
|
69
|
+
expect(opt.options).to eq clean
|
70
70
|
opt.parse!(%w(--opt-1 hi))
|
71
|
-
opt.options.
|
71
|
+
expect(opt.options).to eq expected
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'supports adding an option with a parameter and type' do
|
@@ -76,15 +76,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
76
76
|
clean = { opt1: nil }
|
77
77
|
opt = Option1.new
|
78
78
|
opt.option_with_param :opt1, ['-1', '--opt-1 PARAM'], type: Integer
|
79
|
-
opt.options.
|
79
|
+
expect(opt.options).to eq clean
|
80
80
|
opt.default_options opt1: nil
|
81
|
-
opt.options.
|
81
|
+
expect(opt.options).to eq clean
|
82
82
|
opt.parse!(%w(-1 1))
|
83
|
-
opt.options.
|
83
|
+
expect(opt.options).to eq expected
|
84
84
|
opt.default_options opt1: nil
|
85
|
-
opt.options.
|
85
|
+
expect(opt.options).to eq clean
|
86
86
|
opt.parse!(%w(--opt-1 1))
|
87
|
-
opt.options.
|
87
|
+
expect(opt.options).to eq expected
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'supports adding an option with a parameter that store multiple instances' do
|
@@ -92,23 +92,23 @@ describe EverydayCliUtils::OptionUtil do
|
|
92
92
|
clean = { opt1: [] }
|
93
93
|
opt = Option1.new
|
94
94
|
opt.option_with_param :opt1, ['-1', '--opt-1 PARAM'], append: true
|
95
|
-
opt.options.
|
95
|
+
expect(opt.options).to eq clean
|
96
96
|
opt.default_options opt1: []
|
97
|
-
opt.options.
|
97
|
+
expect(opt.options).to eq clean
|
98
98
|
opt.parse!(%w(-1 hi -1 bye))
|
99
|
-
opt.options.
|
99
|
+
expect(opt.options).to eq expected
|
100
100
|
opt.default_options opt1: []
|
101
|
-
opt.options.
|
101
|
+
expect(opt.options).to eq clean
|
102
102
|
opt.parse!(%w(--opt-1 hi --opt-1 bye))
|
103
|
-
opt.options.
|
103
|
+
expect(opt.options).to eq expected
|
104
104
|
opt.default_options opt1: []
|
105
|
-
opt.options.
|
105
|
+
expect(opt.options).to eq clean
|
106
106
|
opt.parse!(%w(-1 hi --opt-1 bye))
|
107
|
-
opt.options.
|
107
|
+
expect(opt.options).to eq expected
|
108
108
|
opt.default_options opt1: []
|
109
|
-
opt.options.
|
109
|
+
expect(opt.options).to eq clean
|
110
110
|
opt.parse!(%w(--opt-1 hi -1 bye))
|
111
|
-
opt.options.
|
111
|
+
expect(opt.options).to eq expected
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'supports setting the default for the toggle setting' do
|
@@ -117,15 +117,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
117
117
|
opt = Option1.new
|
118
118
|
opt.default_settings toggle: true
|
119
119
|
opt.option :opt1, %w(-1 --opt-1)
|
120
|
-
opt.options.
|
120
|
+
expect(opt.options).to eq expected
|
121
121
|
opt.default_options opt1: true
|
122
|
-
opt.options.
|
122
|
+
expect(opt.options).to eq clean
|
123
123
|
opt.parse!(['-1'])
|
124
|
-
opt.options.
|
124
|
+
expect(opt.options).to eq expected
|
125
125
|
opt.default_options opt1: true
|
126
|
-
opt.options.
|
126
|
+
expect(opt.options).to eq clean
|
127
127
|
opt.parse!(['--opt-1'])
|
128
|
-
opt.options.
|
128
|
+
expect(opt.options).to eq expected
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'supports setting the default for the type setting' do
|
@@ -134,15 +134,15 @@ describe EverydayCliUtils::OptionUtil do
|
|
134
134
|
opt = Option1.new
|
135
135
|
opt.default_settings type: Integer
|
136
136
|
opt.option_with_param :opt1, ['-1', '--opt-1 PARAM']
|
137
|
-
opt.options.
|
137
|
+
expect(opt.options).to eq clean
|
138
138
|
opt.default_options opt1: nil
|
139
|
-
opt.options.
|
139
|
+
expect(opt.options).to eq clean
|
140
140
|
opt.parse!(%w(-1 1))
|
141
|
-
opt.options.
|
141
|
+
expect(opt.options).to eq expected
|
142
142
|
opt.default_options opt1: nil
|
143
|
-
opt.options.
|
143
|
+
expect(opt.options).to eq clean
|
144
144
|
opt.parse!(%w(--opt-1 1))
|
145
|
-
opt.options.
|
145
|
+
expect(opt.options).to eq expected
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'supports adding an option with a parameter that store multiple instances' do
|
@@ -151,23 +151,23 @@ describe EverydayCliUtils::OptionUtil do
|
|
151
151
|
opt = Option1.new
|
152
152
|
opt.default_settings append: true
|
153
153
|
opt.option_with_param :opt1, ['-1', '--opt-1 PARAM']
|
154
|
-
opt.options.
|
154
|
+
expect(opt.options).to eq clean
|
155
155
|
opt.default_options opt1: []
|
156
|
-
opt.options.
|
156
|
+
expect(opt.options).to eq clean
|
157
157
|
opt.parse!(%w(-1 hi -1 bye))
|
158
|
-
opt.options.
|
158
|
+
expect(opt.options).to eq expected
|
159
159
|
opt.default_options opt1: []
|
160
|
-
opt.options.
|
160
|
+
expect(opt.options).to eq clean
|
161
161
|
opt.parse!(%w(--opt-1 hi --opt-1 bye))
|
162
|
-
opt.options.
|
162
|
+
expect(opt.options).to eq expected
|
163
163
|
opt.default_options opt1: []
|
164
|
-
opt.options.
|
164
|
+
expect(opt.options).to eq clean
|
165
165
|
opt.parse!(%w(-1 hi --opt-1 bye))
|
166
|
-
opt.options.
|
166
|
+
expect(opt.options).to eq expected
|
167
167
|
opt.default_options opt1: []
|
168
|
-
opt.options.
|
168
|
+
expect(opt.options).to eq clean
|
169
169
|
opt.parse!(%w(--opt-1 hi -1 bye))
|
170
|
-
opt.options.
|
170
|
+
expect(opt.options).to eq expected
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'supports setting a banner and description' do
|
@@ -181,7 +181,7 @@ describe EverydayCliUtils::OptionUtil do
|
|
181
181
|
-2, --opt-2 PARAM option #2 (takes parameter)
|
182
182
|
-0, --set-defaults set defaults
|
183
183
|
'
|
184
|
-
opt.to_s.
|
184
|
+
expect(opt.to_s).to eq expected
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'supports layers' do
|
@@ -200,8 +200,8 @@ describe EverydayCliUtils::OptionUtil do
|
|
200
200
|
opt.option_with_param :opt2, %w(-2 --big-opt-2)
|
201
201
|
opt.option_with_param :opt3, %w(-3 --bigger-opt-3), append: false
|
202
202
|
opt.option_with_param :opt4, %w(-4 --even-bigger-opt-4), type: Integer
|
203
|
-
opt.options.
|
204
|
-
opt.option_list.show_defaults.
|
203
|
+
expect(opt.options).to eq clean
|
204
|
+
expect(opt.option_list.show_defaults).to eq <<SHOW
|
205
205
|
Script Defaults:
|
206
206
|
-1, --opt-1 false
|
207
207
|
-2 PARAM, --big-opt-2 []
|
@@ -210,8 +210,8 @@ Script Defaults:
|
|
210
210
|
|
211
211
|
SHOW
|
212
212
|
opt.default_options opt1: true
|
213
|
-
opt.options.
|
214
|
-
opt.option_list.show_defaults.
|
213
|
+
expect(opt.options).to eq clean2
|
214
|
+
expect(opt.option_list.show_defaults).to eq <<SHOW
|
215
215
|
Script Defaults:
|
216
216
|
-1, --opt-1 true
|
217
217
|
-2 PARAM, --big-opt-2 []
|
@@ -220,8 +220,8 @@ Script Defaults:
|
|
220
220
|
|
221
221
|
SHOW
|
222
222
|
opt.apply_options :global, opt1: true, opt3: 'hi', opt4: [5]
|
223
|
-
opt.options.
|
224
|
-
opt.option_list.show_defaults.
|
223
|
+
expect(opt.options).to eq global
|
224
|
+
expect(opt.option_list.show_defaults).to eq <<SHOW
|
225
225
|
Script Defaults:
|
226
226
|
-1, --opt-1 true
|
227
227
|
-2 PARAM, --big-opt-2 []
|
@@ -235,8 +235,8 @@ Script + Global Defaults:
|
|
235
235
|
|
236
236
|
SHOW
|
237
237
|
opt.apply_options :local, opt1: false, opt2: %w(hi bye), opt3: 'bye', opt4: [4]
|
238
|
-
opt.options.
|
239
|
-
opt.option_list.show_defaults.
|
238
|
+
expect(opt.options).to eq global_local
|
239
|
+
expect(opt.option_list.show_defaults).to eq <<SHOW
|
240
240
|
Script Defaults:
|
241
241
|
-1, --opt-1 true
|
242
242
|
-2 PARAM, --big-opt-2 []
|
@@ -255,13 +255,13 @@ Script + Global + Local Defaults:
|
|
255
255
|
|
256
256
|
SHOW
|
257
257
|
opt.apply_options :arg, opt1: true
|
258
|
-
opt.options.
|
259
|
-
opt.option_list.composite(:global, :arg).
|
260
|
-
opt.option_list.composite(:global, :local).
|
261
|
-
opt.option_list.composite(:global).
|
262
|
-
opt.option_list.composite(:local).
|
263
|
-
opt.option_list.composite(:local, :arg).
|
264
|
-
opt.option_list.composite(:arg).
|
265
|
-
opt.option_list.composite(:global, :local, :arg).
|
258
|
+
expect(opt.options).to eq total
|
259
|
+
expect(opt.option_list.composite(:global, :arg)).to eq global_arg
|
260
|
+
expect(opt.option_list.composite(:global, :local)).to eq global_local
|
261
|
+
expect(opt.option_list.composite(:global)).to eq global
|
262
|
+
expect(opt.option_list.composite(:local)).to eq local
|
263
|
+
expect(opt.option_list.composite(:local, :arg)).to eq local_arg
|
264
|
+
expect(opt.option_list.composite(:arg)).to eq arg
|
265
|
+
expect(opt.option_list.composite(:global, :local, :arg)).to eq total
|
266
266
|
end
|
267
267
|
end
|
@@ -12,7 +12,7 @@ describe 'override' do
|
|
12
12
|
it 'supports overriding methods' do
|
13
13
|
arr = [1, 2, 3]
|
14
14
|
arr.override(:first) { "Boo! #{self.overrides.first}"}
|
15
|
-
arr.first.
|
15
|
+
expect(arr.first).to eq 'Boo! 1'
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'supports overriding methods multiple times' do
|
@@ -20,14 +20,14 @@ describe 'override' do
|
|
20
20
|
arr.override(:first) { "Boo! #{self.overrides.first}" }
|
21
21
|
arr.override(:first) { "Boo Again! #{self.overrides[1].first}" }
|
22
22
|
arr.override(:first) { "Boo Again Again! #{self.overrides[1].first} | #{self.overrides.first}" }
|
23
|
-
arr.first.
|
23
|
+
expect(arr.first).to eq 'Boo Again Again! Boo! 1 | Boo Again! 1'
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'supports overriding methods multiple times on a class' do
|
27
27
|
TestClass.override(:test) { |t| "Boo! #{self.overrides.test("-#{t}-")}" }
|
28
28
|
TestClass.override(:test) { |t| "Boo Again! #{self.overrides[1].test("+#{t}+")}" }
|
29
29
|
TestClass.override(:test) { |t| "Boo Again Again! #{self.overrides[1].test("!#{t}!")} | #{self.overrides.test("~#{t}~")}" }
|
30
|
-
TestClass.new.test('Eric').
|
30
|
+
expect(TestClass.new.test('Eric')).to eq 'Boo Again Again! Boo! Hi -!Eric!-! | Boo Again! Hi +~Eric~+!'
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'supports calling methods defined by Object that do not trigger method_missing' do
|
@@ -35,7 +35,7 @@ describe 'override' do
|
|
35
35
|
arr.override(:inspect) { "Boo! #{self.overrides.call_override :inspect}" }
|
36
36
|
arr.override(:inspect) { "Boo Again! #{self.overrides[1].call_override :inspect}" }
|
37
37
|
arr.override(:inspect) { "Boo Again Again! #{self.overrides[1].call_override :inspect} | #{self.overrides.call_override :inspect}" }
|
38
|
-
arr.inspect.
|
38
|
+
expect(arr.inspect).to eq 'Boo Again Again! Boo! [1, 2, 3] | Boo Again! [1, 2, 3]'
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'supports calling methods on the overrides object that were not overridden' do
|
@@ -43,6 +43,6 @@ describe 'override' do
|
|
43
43
|
arr.override(:first) { "Boo! #{self.overrides.first}" }
|
44
44
|
arr.override(:first) { "Boo Again! #{self.overrides[1].first}" }
|
45
45
|
arr.override(:first) { "Boo Again Again! #{self.overrides[1].first} | #{self.overrides.first} || #{self.overrides.last}" }
|
46
|
-
arr.first.
|
46
|
+
expect(arr.first).to eq 'Boo Again Again! Boo! 1 | Boo Again! 1 || 3'
|
47
47
|
end
|
48
48
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everyday-cli-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Henderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: simplecov
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.8.2
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.8.2
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: coveralls
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.7.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.7.0
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: rspec
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,7 +62,6 @@ executables: []
|
|
90
62
|
extensions: []
|
91
63
|
extra_rdoc_files: []
|
92
64
|
files:
|
93
|
-
- ".coveralls.yml"
|
94
65
|
- ".gitignore"
|
95
66
|
- ".rspec"
|
96
67
|
- ".travis.yml"
|
@@ -139,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
110
|
version: '0'
|
140
111
|
requirements: []
|
141
112
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.4.2
|
143
114
|
signing_key:
|
144
115
|
specification_version: 4
|
145
116
|
summary: A few CLI and general utils
|
@@ -150,4 +121,3 @@ test_files:
|
|
150
121
|
- spec/everyday-cli-utils/option_spec.rb
|
151
122
|
- spec/everyday-cli-utils/override_spec.rb
|
152
123
|
- spec/spec_helper.rb
|
153
|
-
has_rdoc:
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
service_name: travis-ci
|