cliprompt 0.1.0 → 0.1.1
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/README.md +2 -1
- data/lib/cliprompt/optionset.rb +1 -0
- data/lib/cliprompt/version.rb +1 -1
- data/lib/cliprompt.rb +9 -0
- data/spec/lib/cliprompt/optionset_spec.rb +8 -8
- data/spec/lib/cliprompt_spec.rb +8 -8
- data/spec/spec_helper.rb +0 -3
- metadata +9 -33
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -23
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/.travis.yml +0 -8
- data/CHANGELOG.md +0 -42
- data/Gemfile +0 -4
- data/Rakefile +0 -14
- data/cliprompt.gemspec +0 -29
- data/example.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d11cf88a04a54a9de51a6c0c4b13f10e990742
|
4
|
+
data.tar.gz: 26f54665588aca02d7eab0ed3d854a996b1452f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28dbc268c87c25ced11fdb697e44edbcf916442f155eae97410e2ce4e9325e29eb492e305403e10bd27bfb1816559389a2d270d730237236a298a4db92114b2d
|
7
|
+
data.tar.gz: bb58e7977ac42c5642674eb78672ae02224bab65d74daa98b3d395e51b340f51b5a372c58417eeb8525a782e0b03d1df82feda73223bf0cf8fcefe15f40d4e2d
|
data/README.md
CHANGED
@@ -2,16 +2,17 @@ Cliprompt
|
|
2
2
|
==============
|
3
3
|
|
4
4
|
[](http://rubygems.org/gems/cliprompt)
|
5
|
+
[](https://rubygems.org/gems/cliprompt)
|
5
6
|
[](https://travis-ci.org/mose/cliprompt)
|
6
7
|
[](https://coveralls.io/r/mose/cliprompt?branch=master)
|
7
8
|
[](https://gemnasium.com/mose/cliprompt)
|
8
9
|
[](https://codeclimate.com/github/mose/cliprompt)
|
10
|
+
[](https://inch-ci.org/github/mose/cliprompt)
|
9
11
|
|
10
12
|
This library provides a simple DSL for managing user interaction in a CLI application. Still under development, but usable already. Check the [Changelog](https://github.com/mose/cliprompt/blob/master/CHANGELOG.md) to see what is in already.
|
11
13
|
|
12
14
|
Features
|
13
15
|
----------
|
14
|
-
|
15
16
|
- manages questions, choices, default values, yes/no values (done)
|
16
17
|
- makes possible to have env vars set for defaults (done)
|
17
18
|
|
data/lib/cliprompt/optionset.rb
CHANGED
data/lib/cliprompt/version.rb
CHANGED
data/lib/cliprompt.rb
CHANGED
@@ -13,6 +13,7 @@ module Cliprompt
|
|
13
13
|
MSG_INPUT_A_NUMBER = "You need input a number."
|
14
14
|
MSG_CHOSE_A_NUMBER = "Choose a number:"
|
15
15
|
|
16
|
+
# interactive setup of option
|
16
17
|
def ask(question, *options)
|
17
18
|
if options[0].class == Optionset
|
18
19
|
opts = options[0]
|
@@ -25,6 +26,7 @@ module Cliprompt
|
|
25
26
|
opts.validate(question, answer)
|
26
27
|
end
|
27
28
|
|
29
|
+
# if environment var is set, use it, otherwise, ask for a value
|
28
30
|
def guess(env, question, *options)
|
29
31
|
opts = Optionset.new(*options)
|
30
32
|
if ENV[env]
|
@@ -34,23 +36,30 @@ module Cliprompt
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
39
|
+
# output a message
|
40
|
+
# message - string to output
|
37
41
|
def say(message)
|
38
42
|
output.puts message
|
39
43
|
end
|
40
44
|
|
45
|
+
# paints a message in bold and red and output it
|
46
|
+
# message - string to paint
|
41
47
|
def shout(message)
|
42
48
|
output.puts Paint[message, :bold, :red ]
|
43
49
|
end
|
44
50
|
|
51
|
+
# makes possible to set input and output
|
45
52
|
def setio(input, output)
|
46
53
|
@@input = input
|
47
54
|
@@output = output
|
48
55
|
end
|
49
56
|
|
57
|
+
# defaults to STDIN
|
50
58
|
def input
|
51
59
|
@@input ||= STDIN
|
52
60
|
end
|
53
61
|
|
62
|
+
# defaults to STDOUT
|
54
63
|
def output
|
55
64
|
@@output ||= STDOUT
|
56
65
|
end
|
@@ -194,21 +194,21 @@ describe Cliprompt::Optionset do
|
|
194
194
|
context 'when enter key is hit,' do
|
195
195
|
Given(:input) { '' }
|
196
196
|
Given(:set) { Cliprompt::Optionset.new() }
|
197
|
-
When { set.
|
197
|
+
When { allow(set).to receive(:check_default).with(question) }
|
198
198
|
Then { expect(set).to receive(:check_default).with(question) }
|
199
199
|
And { expect{ set.validate(question, input) }.not_to raise_error }
|
200
200
|
end
|
201
201
|
context 'when it is a boolean,' do
|
202
202
|
Given(:input) { 'x' }
|
203
203
|
Given(:set) { Cliprompt::Optionset.new(boolean: true) }
|
204
|
-
When { set.
|
204
|
+
When { allow(set).to receive(:check_boolean).with(question, input) }
|
205
205
|
Then { expect(set).to receive(:check_boolean).with(question, input) }
|
206
206
|
And { expect{ set.validate(question, input) }.not_to raise_error }
|
207
207
|
end
|
208
208
|
context 'when it is a choice list,' do
|
209
209
|
Given(:input) { 'x' }
|
210
210
|
Given(:set) { Cliprompt::Optionset.new(choices: [1,2,3]) }
|
211
|
-
When { set.
|
211
|
+
When { allow(set).to receive(:check_choices).with(question, input) }
|
212
212
|
Then { expect(set).to receive(:check_choices).with(question, input) }
|
213
213
|
And { expect{ set.validate(question, input) }.not_to raise_error }
|
214
214
|
end
|
@@ -224,7 +224,7 @@ describe Cliprompt::Optionset do
|
|
224
224
|
Given(:msg) { Cliprompt::MSG_MANDATORY_TEXT }
|
225
225
|
context 'when there is no default set,' do
|
226
226
|
Given(:set) { Cliprompt::Optionset.new() }
|
227
|
-
When { set.
|
227
|
+
When { allow(set).to receive(:ask_again).with(question, msg) }
|
228
228
|
Then { expect(set).to receive(:ask_again).with(question, msg) }
|
229
229
|
And { expect{ set.check_default(question) }.not_to raise_error }
|
230
230
|
end
|
@@ -243,7 +243,7 @@ describe Cliprompt::Optionset do
|
|
243
243
|
Given(:set) { Cliprompt::Optionset.new(boolean: true) }
|
244
244
|
context 'when a non yes-no answer is given,' do
|
245
245
|
When(:input) { 'xxx' }
|
246
|
-
When { set.
|
246
|
+
When { allow(set).to receive(:ask_again).with(question, msg) }
|
247
247
|
Then { expect(set).to receive(:ask_again).with(question, msg) }
|
248
248
|
And { expect{ set.check_boolean(question, input) }.not_to raise_error }
|
249
249
|
end
|
@@ -272,7 +272,7 @@ describe Cliprompt::Optionset do
|
|
272
272
|
Given(:set) { Cliprompt::Optionset.new(choices: choices) }
|
273
273
|
context 'when answer is not in choices list,' do
|
274
274
|
When(:input) { 'x' }
|
275
|
-
When { set.
|
275
|
+
When { allow(set).to receive(:ask_again).with(question, msg) }
|
276
276
|
Then { expect(set).to receive(:ask_again).with(question, msg) }
|
277
277
|
And { expect{ set.check_choices(question, input) }.not_to raise_error }
|
278
278
|
end
|
@@ -287,8 +287,8 @@ describe Cliprompt::Optionset do
|
|
287
287
|
Given(:question) { 'so what?' }
|
288
288
|
Given(:msg) { 'heho gimme something' }
|
289
289
|
Given(:set) { Cliprompt::Optionset.new() }
|
290
|
-
When { Cliprompt.
|
291
|
-
When { Cliprompt.
|
290
|
+
When { allow(Cliprompt).to receive(:shout).with(msg) }
|
291
|
+
When { allow(Cliprompt).to receive(:ask).with(question, set) }
|
292
292
|
Then { expect(Cliprompt).to receive(:shout).with(msg) }
|
293
293
|
And { expect(Cliprompt).to receive(:ask).with(question, set) }
|
294
294
|
And { expect{ set.ask_again(question, msg)}.not_to raise_error }
|
data/spec/lib/cliprompt_spec.rb
CHANGED
@@ -14,44 +14,44 @@ describe Cliprompt do
|
|
14
14
|
Given(:answer) { 'xxx' }
|
15
15
|
context 'without default,' do
|
16
16
|
When(:args) { }
|
17
|
-
When { input.
|
17
|
+
When { allow(input).to receive(:gets).and_return answer }
|
18
18
|
Then { expect(subject.ask(question, args)).to eq answer }
|
19
19
|
And { expect(output.string).to eq "#{question} " }
|
20
20
|
end
|
21
21
|
context 'with a default,' do
|
22
22
|
When(:default) { 'ooo' }
|
23
23
|
When(:args) { { default: default } }
|
24
|
-
When { input.
|
24
|
+
When { allow(input).to receive(:gets).and_return answer }
|
25
25
|
Then { expect(subject.ask(question, args)).to eq answer }
|
26
26
|
And { expect(output.string).to eq "#{question} [#{default}] " }
|
27
27
|
end
|
28
28
|
context 'with an optionset,' do
|
29
29
|
When(:args) { Cliprompt::Optionset.new() }
|
30
|
-
When { input.
|
30
|
+
When { allow(input).to receive(:gets).and_return answer }
|
31
31
|
Then { expect(subject.ask(question, args)).to eq answer }
|
32
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
|
-
When { input.
|
36
|
+
When { allow(input).to receive(:gets).and_return '1' }
|
37
37
|
Then { expect(subject.ask(question, args)).to eq 'bbb' }
|
38
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
|
-
When { input.
|
42
|
+
When { allow(input).to receive(:gets).and_return '' }
|
43
43
|
Then { expect(subject.ask(question, args)).to eq 'aaa' }
|
44
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 } }
|
48
|
-
When { input.
|
48
|
+
When { allow(input).to receive(:gets).and_return 'bbb' }
|
49
49
|
Then { expect(subject.ask(question, args)).to eq 'bbb' }
|
50
50
|
And { expect(output.string).to eq "#{question} (aaa / bbb / ccc / ddd / eee / fff) " }
|
51
51
|
end
|
52
52
|
context 'with a big list of choices,' do
|
53
53
|
When(:args) { %w(aaa bbb ccc ddd eee fff) }
|
54
|
-
When { input.
|
54
|
+
When { allow(input).to receive(:gets).and_return '5' }
|
55
55
|
Then { expect(subject.ask(question, args)).to eq 'fff' }
|
56
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
|
@@ -69,7 +69,7 @@ describe Cliprompt do
|
|
69
69
|
end
|
70
70
|
context 'when env var is not provided,' do
|
71
71
|
When(:answer) { 'ooo' }
|
72
|
-
When { input.
|
72
|
+
When { allow(input).to receive(:gets).and_return answer }
|
73
73
|
Then { expect(subject.guess(env_var, question, args)).to eq answer }
|
74
74
|
And { expect(output.string).to eq "#{question} " }
|
75
75
|
end
|
data/spec/spec_helper.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paint
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-given
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: coveralls
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: codeclimate-test-reporter
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,18 +102,8 @@ executables: []
|
|
116
102
|
extensions: []
|
117
103
|
extra_rdoc_files: []
|
118
104
|
files:
|
119
|
-
- ".coveralls.yml"
|
120
|
-
- ".gitignore"
|
121
|
-
- ".rspec"
|
122
|
-
- ".ruby-version"
|
123
|
-
- ".travis.yml"
|
124
|
-
- CHANGELOG.md
|
125
|
-
- Gemfile
|
126
105
|
- LICENSE
|
127
106
|
- README.md
|
128
|
-
- Rakefile
|
129
|
-
- cliprompt.gemspec
|
130
|
-
- example.rb
|
131
107
|
- lib/cliprompt.rb
|
132
108
|
- lib/cliprompt/optionset.rb
|
133
109
|
- lib/cliprompt/version.rb
|
@@ -154,11 +130,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
130
|
version: '0'
|
155
131
|
requirements: []
|
156
132
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.4.8
|
158
134
|
signing_key:
|
159
135
|
specification_version: 4
|
160
136
|
summary: Env aware lib for CLI prompt.
|
161
137
|
test_files:
|
162
|
-
- spec/lib/cliprompt/optionset_spec.rb
|
163
|
-
- spec/lib/cliprompt_spec.rb
|
164
138
|
- spec/spec_helper.rb
|
139
|
+
- spec/lib/cliprompt_spec.rb
|
140
|
+
- spec/lib/cliprompt/optionset_spec.rb
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
repo_token: k1iNRfDdAPW1ajziFDqPE0sZHTfbCtyA2
|
data/.gitignore
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
23
|
-
vendor/
|
data/.rspec
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.1
|
data/.travis.yml
DELETED
data/CHANGELOG.md
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
Cliprompt Changelog
|
2
|
-
=====================
|
3
|
-
|
4
|
-
v0.1.0 - 2014-05-10
|
5
|
-
-------------------
|
6
|
-
|
7
|
-
- fix tests for rspec 3 compliance
|
8
|
-
|
9
|
-
v0.0.6 - 2014-08-10
|
10
|
-
--------------------
|
11
|
-
|
12
|
-
- fix validation of list type to be a number
|
13
|
-
|
14
|
-
v0.0.5 - 2014-05-27
|
15
|
-
--------------------
|
16
|
-
|
17
|
-
- fix to one space after question that was 2 spaces when no default is provided
|
18
|
-
- when choices are a list, show the default in the question, in more than in the list
|
19
|
-
- clean some ruby warnings (running with --debug helps)
|
20
|
-
|
21
|
-
v0.0.4 - 2014-05-24
|
22
|
-
--------------------
|
23
|
-
|
24
|
-
- add an option `aslist` for we can decide if we want it as a list or not
|
25
|
-
- add a way to display big list, when choices are more than 5, make a list out of them
|
26
|
-
|
27
|
-
v0.0.3 - 2014-05-20
|
28
|
-
--------------------
|
29
|
-
|
30
|
-
- relax the boolean check so 1 and 0 can be used for yes and no (especially for env vars)
|
31
|
-
- added a `guess` method to have env var override question if set
|
32
|
-
|
33
|
-
v0.0.2 - 2014-05-20
|
34
|
-
--------------------
|
35
|
-
|
36
|
-
- fix case when numbers are used in choices
|
37
|
-
- added some test coverage for further evolution easiness
|
38
|
-
|
39
|
-
v0.0.1 - 2014-05-19
|
40
|
-
--------------------
|
41
|
-
|
42
|
-
- first draft
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rspec/core/rake_task' # RSpec 2.0
|
5
|
-
|
6
|
-
desc 'launch rspec tests'
|
7
|
-
task :spec do
|
8
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
-
t.rspec_opts = ['-c', '-f progress', '-r ./spec/spec_helper.rb']
|
10
|
-
t.pattern = 'spec/lib/**/*_spec.rb'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
task default: :spec
|
data/cliprompt.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'cliprompt/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "cliprompt"
|
8
|
-
spec.version = Cliprompt::VERSION
|
9
|
-
spec.authors = ["mose"]
|
10
|
-
spec.email = ["mose@mose.com"]
|
11
|
-
spec.summary = %q{Env aware lib for CLI prompt.}
|
12
|
-
spec.description = %q{This library provides a simple DSL for managing user interaction in a CLI application.}
|
13
|
-
spec.homepage = "https://github.com/mose/cliprompt"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency 'paint'
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'rspec-given'
|
27
|
-
spec.add_development_dependency 'coveralls'
|
28
|
-
spec.add_development_dependency 'codeclimate-test-reporter'
|
29
|
-
end
|
data/example.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require_relative 'lib/cliprompt'
|
2
|
-
|
3
|
-
class Myclass
|
4
|
-
include Cliprompt
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
end
|
8
|
-
|
9
|
-
def askit
|
10
|
-
puts '-------------------'
|
11
|
-
puts 'numeric default'
|
12
|
-
show "what is your age?", 42
|
13
|
-
show "what is your size?", 6.2
|
14
|
-
puts '-------------------'
|
15
|
-
puts 'Free form'
|
16
|
-
show "This simply ask for a simple form mandatory thing?"
|
17
|
-
show "This simply ask for a simple form mandatory thing?", 'with a default'
|
18
|
-
show "This simply ask for a simple form mandatory thing?", default: 'with a default again'
|
19
|
-
puts '-------------------'
|
20
|
-
puts 'yes/no'
|
21
|
-
show 'a boolean?', 'y/N'
|
22
|
-
show 'a boolean?', 'yN'
|
23
|
-
show 'a boolean?', 'yesno'
|
24
|
-
show 'a boolean?', 'yesNo'
|
25
|
-
show 'a boolean?', boolean: true
|
26
|
-
show 'a boolean?', boolean: true, default: false
|
27
|
-
puts '-------------------'
|
28
|
-
puts 'a list of choices'
|
29
|
-
show 'a list without default?', [22, 33, 44, '55']
|
30
|
-
show 'a list with default?', ['22', '33', '=44', '55']
|
31
|
-
show 'a list without default?', choices: ['22', '33', '44', '55'], default: 22
|
32
|
-
show 'a list with default?', choices: ['22', 33, '=44', '55']
|
33
|
-
end
|
34
|
-
|
35
|
-
def guessit
|
36
|
-
puts '-------------------'
|
37
|
-
showguess 'SOMEVAR', "what is your var?"
|
38
|
-
showguess 'SOMEVAR', "what is your var?", 42
|
39
|
-
showguess 'SOMEVAR', "what is your var?", boolean: true
|
40
|
-
showguess 'SOMEVAR', "what is your var?", [12, 'aa']
|
41
|
-
end
|
42
|
-
|
43
|
-
def biglist
|
44
|
-
puts '-------------------'
|
45
|
-
puts 'a long list of choices'
|
46
|
-
show 'a list with default?', [22, 33, 44, '=55', 66, 77, 'something else']
|
47
|
-
show 'a list without default?', [22, 33, 44, '55', 66, 77, 'something else']
|
48
|
-
show 'a big list of choices but not in list?', choices: [22, 33, 44, '=55', 66, 77, 'something else'], aslist: false
|
49
|
-
show 'a small list of choices but we want it in list?', choices: [22, 33, '=44'], aslist: true
|
50
|
-
end
|
51
|
-
|
52
|
-
def show(*args)
|
53
|
-
it = ask *args
|
54
|
-
puts "-- returned #{it.inspect}"
|
55
|
-
puts
|
56
|
-
end
|
57
|
-
|
58
|
-
def showguess(*args)
|
59
|
-
it = guess *args
|
60
|
-
puts "-- returned #{it.inspect}"
|
61
|
-
puts
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
m = Myclass.new
|
67
|
-
m.guessit
|
68
|
-
m.askit
|
69
|
-
m.biglist
|