cliprompt 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/example.rb +2 -2
- data/lib/cliprompt.rb +3 -15
- data/lib/cliprompt/optionset.rb +43 -7
- data/lib/cliprompt/version.rb +1 -1
- data/spec/lib/cliprompt/optionset_spec.rb +17 -15
- data/spec/lib/cliprompt_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61b352cf68eda3ca18f4051cacd85dd3047ac665
|
4
|
+
data.tar.gz: 156fb8f2414b6f4eee18ddb63ac8c05b25f33673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be597dccf32f0a9c761b2b7d88b4af36040cfa91942371f8f64d99263ad5346e976d36b66bb38b9b8e4449b43ca023ba1b3d787142136a9ee8a970c07843520a
|
7
|
+
data.tar.gz: 03fd5bd35e18510a1b30c06e87c46e6122948f05ae2629bf23b6b2346fb5b15407d539feede545c4b69e3cc78dab94c6bcb0c176b194e5f3119819c33b1db79c
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
Cliprompt Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
v0.0.5 - 2014-05-27
|
5
|
+
--------------------
|
6
|
+
|
7
|
+
- fix to one space after question that was 2 spaces when no default is provided
|
8
|
+
- when choices are a list, show the default in the question, in more than in the list
|
9
|
+
- clean some ruby warnings (running with --debug helps)
|
10
|
+
|
4
11
|
v0.0.4 - 2014-05-24
|
5
12
|
--------------------
|
6
13
|
|
data/example.rb
CHANGED
data/lib/cliprompt.rb
CHANGED
@@ -16,28 +16,16 @@ module Cliprompt
|
|
16
16
|
if options[0].class == Optionset
|
17
17
|
opts = options[0]
|
18
18
|
else
|
19
|
-
opts = Optionset.new
|
20
|
-
end
|
21
|
-
if opts.aslist
|
22
|
-
output.puts "#{question}"
|
23
|
-
opts.choices.each_with_index do |choice, i|
|
24
|
-
if opts.default == choice
|
25
|
-
output.printf "> %-3s %s\n", i, choice
|
26
|
-
else
|
27
|
-
output.printf " %-3s %s\n", i, choice
|
28
|
-
end
|
29
|
-
end
|
30
|
-
output.print "#{MSG_CHOSE_A_NUMBER} "
|
31
|
-
else
|
32
|
-
output.print "#{question} #{opts.display} "
|
19
|
+
opts = Optionset.new(*options)
|
33
20
|
end
|
21
|
+
output.print "#{question} #{opts.display}"
|
34
22
|
answer = input.gets.chomp
|
35
23
|
output.flush
|
36
24
|
opts.validate(question, answer)
|
37
25
|
end
|
38
26
|
|
39
27
|
def guess(env, question, *options)
|
40
|
-
opts = Optionset.new
|
28
|
+
opts = Optionset.new(*options)
|
41
29
|
if ENV[env]
|
42
30
|
opts.validate(question, ENV[env])
|
43
31
|
else
|
data/lib/cliprompt/optionset.rb
CHANGED
@@ -63,9 +63,9 @@ module Cliprompt
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def parse_string(arg)
|
66
|
-
if
|
66
|
+
if /^[yY1](es)?(\/)?[nN0](o)?/.match(arg)
|
67
67
|
@boolean = true
|
68
|
-
if /y(es)?(\/)?N/.match
|
68
|
+
if /y(es)?(\/)?N/.match(arg)
|
69
69
|
@default = false
|
70
70
|
else
|
71
71
|
@default = true
|
@@ -76,18 +76,54 @@ module Cliprompt
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def display
|
79
|
-
back = ''
|
80
79
|
if @boolean
|
81
|
-
|
80
|
+
display_boolean
|
81
|
+
elsif @choices.count > 0
|
82
|
+
if @aslist
|
83
|
+
display_list
|
84
|
+
else
|
85
|
+
display_choices
|
86
|
+
end
|
82
87
|
else
|
83
|
-
|
84
|
-
|
88
|
+
display_default
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def display_boolean
|
93
|
+
@default ? "[Y/n] " : "[y/N] "
|
94
|
+
end
|
95
|
+
|
96
|
+
def display_list
|
97
|
+
back = "\n"
|
98
|
+
choices.each_with_index do |choice, i|
|
99
|
+
if @default == choice
|
100
|
+
back << sprintf("> %-3s %s\n", i, choice)
|
101
|
+
else
|
102
|
+
back << sprintf(" %-3s %s\n", i, choice)
|
85
103
|
end
|
86
|
-
back += "[#{@default}]" if @default
|
87
104
|
end
|
105
|
+
back << "#{Cliprompt::MSG_CHOSE_A_NUMBER} "
|
106
|
+
back << display_default_index.to_s
|
107
|
+
return back
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_choices
|
111
|
+
back = ''
|
112
|
+
if @choices.count > 0
|
113
|
+
back << "(#{@choices.join(' / ')}) "
|
114
|
+
end
|
115
|
+
back << display_default.to_s
|
88
116
|
return back
|
89
117
|
end
|
90
118
|
|
119
|
+
def display_default
|
120
|
+
"[#{@default}] " if @default
|
121
|
+
end
|
122
|
+
|
123
|
+
def display_default_index
|
124
|
+
"[#{@choices.index(@default)}] " if @default
|
125
|
+
end
|
126
|
+
|
91
127
|
def validate(question, answer)
|
92
128
|
if answer == ''
|
93
129
|
check_default question
|
data/lib/cliprompt/version.rb
CHANGED
@@ -23,7 +23,7 @@ describe Cliprompt::Optionset do
|
|
23
23
|
When(:display) { set.display }
|
24
24
|
Then { expect(choices).to eq options }
|
25
25
|
Then { expect(default).to be_false }
|
26
|
-
Then { expect(display).to eq '(xxx / yyy / zzz)' }
|
26
|
+
Then { expect(set.display).to eq '(xxx / yyy / zzz) ' }
|
27
27
|
end
|
28
28
|
|
29
29
|
context "when there is a default specified (#{['xxx', '=yyy', 'zzz'].to_s})," do
|
@@ -35,7 +35,7 @@ describe Cliprompt::Optionset do
|
|
35
35
|
When(:display) { set.display }
|
36
36
|
Then { expect(choices).to eq options }
|
37
37
|
Then { expect(default).to eq 'yyy' }
|
38
|
-
Then { expect(display).to eq '(xxx / yyy / zzz)[yyy]' }
|
38
|
+
Then { expect(display).to eq '(xxx / yyy / zzz) [yyy] ' }
|
39
39
|
end
|
40
40
|
|
41
41
|
context "when there is a mixed numeric and string choices (#{[22, 'yyy', 'zzz'].to_s})," do
|
@@ -46,7 +46,7 @@ describe Cliprompt::Optionset do
|
|
46
46
|
When(:display) { set.display }
|
47
47
|
Then { expect(choices).to eq options.map(&:to_s) }
|
48
48
|
Then { expect(default).to be_false }
|
49
|
-
Then { expect(display).to eq '(22 / yyy / zzz)' }
|
49
|
+
Then { expect(display).to eq '(22 / yyy / zzz) ' }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -61,7 +61,7 @@ describe Cliprompt::Optionset do
|
|
61
61
|
When(:display) { set.display }
|
62
62
|
Then { expect(choices).to eq ['xxx', 'yyy', 'zzz'] }
|
63
63
|
Then { expect(default).to eq 'xxx' }
|
64
|
-
Then { expect(display).to eq '(xxx / yyy / zzz)[xxx]' }
|
64
|
+
Then { expect(display).to eq '(xxx / yyy / zzz) [xxx] ' }
|
65
65
|
end
|
66
66
|
context "when using string keys (#{{ 'default' => 'xxx', 'choices' => ['xxx', 'yyy', 'zzz'] }.to_s})," do
|
67
67
|
Given(:options) { { 'default' => 'xxx', 'choices' => ['xxx', 'yyy', 'zzz'] } }
|
@@ -71,12 +71,12 @@ describe Cliprompt::Optionset do
|
|
71
71
|
When(:display) { set.display }
|
72
72
|
Then { expect(choices).to eq ['xxx', 'yyy', 'zzz'] }
|
73
73
|
Then { expect(default).to eq 'xxx' }
|
74
|
-
Then { expect(display).to eq '(xxx / yyy / zzz)[xxx]' }
|
74
|
+
Then { expect(display).to eq '(xxx / yyy / zzz) [xxx] ' }
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'when there is only boolean,' do
|
79
|
-
context 'when
|
79
|
+
context 'when no default is given, default booean is Y,' do
|
80
80
|
Given(:options) { { boolean: true } }
|
81
81
|
Given(:set) { Cliprompt::Optionset.new(options) }
|
82
82
|
When(:default) { set.default }
|
@@ -84,7 +84,7 @@ describe Cliprompt::Optionset do
|
|
84
84
|
When(:boolean) { set.boolean }
|
85
85
|
Then { expect(default).to be_true }
|
86
86
|
Then { expect(boolean).to be_true }
|
87
|
-
Then { expect(display).to eq '[Y/n]' }
|
87
|
+
Then { expect(display).to eq '[Y/n] ' }
|
88
88
|
end
|
89
89
|
context 'when default is given as true, default booean is Y,' do
|
90
90
|
Given(:options) { { boolean: true, default: true } }
|
@@ -94,7 +94,7 @@ describe Cliprompt::Optionset do
|
|
94
94
|
When(:boolean) { set.boolean }
|
95
95
|
Then { expect(default).to be_true }
|
96
96
|
Then { expect(boolean).to be_true }
|
97
|
-
Then { expect(display).to eq '[Y/n]' }
|
97
|
+
Then { expect(display).to eq '[Y/n] ' }
|
98
98
|
end
|
99
99
|
context 'when default is given as false, default boolean is N,' do
|
100
100
|
Given(:options) { { boolean: true, default: false } }
|
@@ -104,7 +104,7 @@ describe Cliprompt::Optionset do
|
|
104
104
|
When(:boolean) { set.boolean }
|
105
105
|
Then { expect(default).to be_false }
|
106
106
|
Then { expect(boolean).to be_true }
|
107
|
-
Then { expect(display).to eq '[y/N]' }
|
107
|
+
Then { expect(display).to eq '[y/N] ' }
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -129,7 +129,9 @@ describe Cliprompt::Optionset do
|
|
129
129
|
Given(:options) { 'something' }
|
130
130
|
Given(:set) { Cliprompt::Optionset.new(options) }
|
131
131
|
When(:default) { set.default }
|
132
|
+
When(:display) { set.display }
|
132
133
|
Then { expect(default).to eq options }
|
134
|
+
Then { expect(display).to eq '[something] ' }
|
133
135
|
end
|
134
136
|
|
135
137
|
context 'when a "yesno" kind of string is passed,' do
|
@@ -141,7 +143,7 @@ describe Cliprompt::Optionset do
|
|
141
143
|
When(:boolean) { set.boolean }
|
142
144
|
Then { expect(default).to be_true }
|
143
145
|
Then { expect(boolean).to be_true }
|
144
|
-
Then { expect(display).to eq '[Y/n]' }
|
146
|
+
Then { expect(display).to eq '[Y/n] ' }
|
145
147
|
end
|
146
148
|
context 'when using yn,' do
|
147
149
|
Given(:options) { 'yn' }
|
@@ -149,7 +151,7 @@ describe Cliprompt::Optionset do
|
|
149
151
|
When(:default) { set.default }
|
150
152
|
When(:display) { set.display }
|
151
153
|
Then { expect(default).to be_true }
|
152
|
-
Then { expect(display).to eq '[Y/n]' }
|
154
|
+
Then { expect(display).to eq '[Y/n] ' }
|
153
155
|
end
|
154
156
|
context 'when using YN,' do
|
155
157
|
Given(:options) { 'YN' }
|
@@ -157,7 +159,7 @@ describe Cliprompt::Optionset do
|
|
157
159
|
When(:default) { set.default }
|
158
160
|
When(:display) { set.display }
|
159
161
|
Then { expect(default).to be_true }
|
160
|
-
Then { expect(display).to eq '[Y/n]' }
|
162
|
+
Then { expect(display).to eq '[Y/n] ' }
|
161
163
|
end
|
162
164
|
context 'when using yesNo,' do
|
163
165
|
Given(:options) { 'yesNo' }
|
@@ -165,7 +167,7 @@ describe Cliprompt::Optionset do
|
|
165
167
|
When(:default) { set.default }
|
166
168
|
When(:display) { set.display }
|
167
169
|
Then { expect(default).to be_false }
|
168
|
-
Then { expect(display).to eq '[y/N]' }
|
170
|
+
Then { expect(display).to eq '[y/N] ' }
|
169
171
|
end
|
170
172
|
context 'when using yN,' do
|
171
173
|
Given(:options) { 'yesNo' }
|
@@ -173,7 +175,7 @@ describe Cliprompt::Optionset do
|
|
173
175
|
When(:default) { set.default }
|
174
176
|
When(:display) { set.display }
|
175
177
|
Then { expect(default).to be_false }
|
176
|
-
Then { expect(display).to eq '[y/N]' }
|
178
|
+
Then { expect(display).to eq '[y/N] ' }
|
177
179
|
end
|
178
180
|
context 'when using y/N,' do
|
179
181
|
Given(:options) { 'yesNo' }
|
@@ -181,7 +183,7 @@ describe Cliprompt::Optionset do
|
|
181
183
|
When(:default) { set.default }
|
182
184
|
When(:display) { set.display }
|
183
185
|
Then { expect(default).to be_false }
|
184
|
-
Then { expect(display).to eq '[y/N]' }
|
186
|
+
Then { expect(display).to eq '[y/N] ' }
|
185
187
|
end
|
186
188
|
end
|
187
189
|
|
data/spec/lib/cliprompt_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe Cliprompt do
|
|
16
16
|
When(:args) { }
|
17
17
|
When { input.stub(:gets).and_return answer }
|
18
18
|
Then { expect(subject.ask(question, args)).to eq answer }
|
19
|
-
And { expect(output.string).to eq "#{question}
|
19
|
+
And { expect(output.string).to eq "#{question} " }
|
20
20
|
end
|
21
21
|
context 'with a default,' do
|
22
22
|
When(:default) { 'ooo' }
|
@@ -29,19 +29,19 @@ describe Cliprompt do
|
|
29
29
|
When(:args) { Cliprompt::Optionset.new() }
|
30
30
|
When { input.stub(:gets).and_return answer }
|
31
31
|
Then { expect(subject.ask(question, args)).to eq answer }
|
32
|
-
And { expect(output.string).to eq "#{question}
|
32
|
+
And { expect(output.string).to eq "#{question} " }
|
33
33
|
end
|
34
34
|
context 'with choices requested as a list,' do
|
35
35
|
When(:args) { { choices: ['aaa', 'bbb', 'ccc'], aslist: true } }
|
36
36
|
When { input.stub(:gets).and_return '1' }
|
37
37
|
Then { expect(subject.ask(question, args)).to eq 'bbb' }
|
38
|
-
And { expect(output.string).to eq "#{question}\n 0 aaa\n 1 bbb\n 2 ccc\n#{Cliprompt::MSG_CHOSE_A_NUMBER} " }
|
38
|
+
And { expect(output.string).to eq "#{question} \n 0 aaa\n 1 bbb\n 2 ccc\n#{Cliprompt::MSG_CHOSE_A_NUMBER} " }
|
39
39
|
end
|
40
40
|
context 'with choices requested as a list with a default,' do
|
41
41
|
When(:args) { { choices: ['=aaa', 'bbb', 'ccc'], aslist: true } }
|
42
42
|
When { input.stub(:gets).and_return '' }
|
43
43
|
Then { expect(subject.ask(question, args)).to eq 'aaa' }
|
44
|
-
And { expect(output.string).to eq "#{question}\n> 0 aaa\n 1 bbb\n 2 ccc\n#{Cliprompt::MSG_CHOSE_A_NUMBER} " }
|
44
|
+
And { expect(output.string).to eq "#{question} \n> 0 aaa\n 1 bbb\n 2 ccc\n#{Cliprompt::MSG_CHOSE_A_NUMBER} [0] " }
|
45
45
|
end
|
46
46
|
context 'with choices requested as a non-list despite there are many choices,' do
|
47
47
|
When(:args) { { choices: %w(aaa bbb ccc ddd eee fff), aslist: false } }
|
@@ -53,7 +53,7 @@ describe Cliprompt do
|
|
53
53
|
When(:args) { %w(aaa bbb ccc ddd eee fff) }
|
54
54
|
When { input.stub(:gets).and_return '5' }
|
55
55
|
Then { expect(subject.ask(question, args)).to eq 'fff' }
|
56
|
-
And { expect(output.string).to eq "#{question}\n 0 aaa\n 1 bbb\n 2 ccc\n 3 ddd\n 4 eee\n 5 fff\n#{Cliprompt::MSG_CHOSE_A_NUMBER} " }
|
56
|
+
And { expect(output.string).to eq "#{question} \n 0 aaa\n 1 bbb\n 2 ccc\n 3 ddd\n 4 eee\n 5 fff\n#{Cliprompt::MSG_CHOSE_A_NUMBER} " }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -71,7 +71,7 @@ describe Cliprompt do
|
|
71
71
|
When(:answer) { 'ooo' }
|
72
72
|
When { input.stub(:gets).and_return answer }
|
73
73
|
Then { expect(subject.guess(env_var, question, args)).to eq answer }
|
74
|
-
And { expect(output.string).to eq "#{question}
|
74
|
+
And { expect(output.string).to eq "#{question} " }
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliprompt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paint
|