cliprompt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +54 -0
- data/Rakefile +14 -0
- data/cliprompt.gemspec +29 -0
- data/example.rb +39 -0
- data/lib/cliprompt/optionset.rb +79 -0
- data/lib/cliprompt/version.rb +3 -0
- data/lib/cliprompt.rb +70 -0
- data/spec/lib/cliprompt/optionset_spec.rb +149 -0
- data/spec/lib/cliprompt_spec.rb +44 -0
- data/spec/spec_helper.rb +26 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03cc6802622eb3c7eb64f31d500a384f5d1ef049
|
4
|
+
data.tar.gz: 20bdbb38baf9f01106dc7f969346467ac6b20a61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58a33b33150b6dd8722725ba1be6c55c77c9b9fb36b9b1ebaad9b7b183c5c3da84e020d065c701d59a092f68550d089044ef1294870b7beb7a43cf7ab2d3881f
|
7
|
+
data.tar.gz: cbb7e51ad1548c61b8c4c33c2ae2ecebd9bbe4e8732fd7abae7146dbc3ad2cd34cef5a3774a536992c1b1ae52212e42736774f434af5710409d06662df3d3468
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: k1iNRfDdAPW1ajziFDqPE0sZHTfbCtyA2
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
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
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mose
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Cliprompt
|
2
|
+
==============
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/mose/cliprompt.png?branch=master)](https://travis-ci.org/mose/cliprompt)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/mose/cliprompt/badge.png?branch=master)](https://coveralls.io/r/mose/cliprompt?branch=master)
|
6
|
+
[![Dependency Status](https://gemnasium.com/mose/cliprompt.svg)](https://gemnasium.com/mose/cliprompt)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/mose/cliprompt.png)](https://codeclimate.com/github/mose/cliprompt)
|
8
|
+
|
9
|
+
This library provides a simple DSL for managing user interaction in a CLI application.
|
10
|
+
|
11
|
+
Features
|
12
|
+
----------
|
13
|
+
|
14
|
+
- manages questions, choices, default values, yes/no values
|
15
|
+
- makes possible to have env vars set for defaults
|
16
|
+
- makes possible to colorize output
|
17
|
+
|
18
|
+
Usage
|
19
|
+
----------
|
20
|
+
|
21
|
+
# add in your Gemfile
|
22
|
+
gem 'cliprompt'
|
23
|
+
|
24
|
+
Then in your code
|
25
|
+
|
26
|
+
```rb
|
27
|
+
require 'cliprompt'
|
28
|
+
|
29
|
+
class Myclass
|
30
|
+
extend Cliprompt
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@url = ask "What is the url of Myclass?"
|
34
|
+
@ssl = ask "Is it using SSL?", 'y/N'
|
35
|
+
@age = ask "What is the age of the captain?", [22,33,=44,55]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Check [example.rb](https://github.com/mose/cliprompt/blob/master/example.rb) for various possible combinations, or run `rspec -f d` after all that's also what tests are for.
|
41
|
+
|
42
|
+
Contributing
|
43
|
+
-----------------
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/cliprompt/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
50
|
+
|
51
|
+
License
|
52
|
+
----------
|
53
|
+
|
54
|
+
Copyrite (c) 2014 - mose - Distributed under MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
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
ADDED
@@ -0,0 +1,29 @@
|
|
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 'dye'
|
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
ADDED
@@ -0,0 +1,39 @@
|
|
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 'Free form'
|
12
|
+
show "This simply ask for a simple form mandatory thing?"
|
13
|
+
show "This simply ask for a simple form mandatory thing?", 'with a default'
|
14
|
+
show "This simply ask for a simple form mandatory thing?", default: 'with a default again'
|
15
|
+
puts '-------------------'
|
16
|
+
puts 'yes/no'
|
17
|
+
show 'a boolean?', 'y/N'
|
18
|
+
show 'a boolean?', 'yN'
|
19
|
+
show 'a boolean?', 'yesno'
|
20
|
+
show 'a boolean?', 'yesNo'
|
21
|
+
show 'a boolean?', boolean: true
|
22
|
+
show 'a boolean?', boolean: true, default: false
|
23
|
+
puts '-------------------'
|
24
|
+
puts 'a list of choices'
|
25
|
+
show 'a list without default?', ['22', '33', '44', '55']
|
26
|
+
show 'a list without default?', choices: ['22', '33', '44', '55'], default: '22'
|
27
|
+
show 'a list with default?', ['22', '33', '=44', '55']
|
28
|
+
show 'a list with default?', choices: ['22', '33', '=44', '55']
|
29
|
+
end
|
30
|
+
|
31
|
+
def show(*args)
|
32
|
+
it = ask *args
|
33
|
+
puts "-- returned #{it.inspect}"
|
34
|
+
puts
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
m = Myclass.new
|
39
|
+
m.askit
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Cliprompt
|
2
|
+
|
3
|
+
class OptionException < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class Optionset
|
7
|
+
|
8
|
+
attr_reader :choices, :default, :boolean, :envdefault
|
9
|
+
|
10
|
+
def initialize(options = nil)
|
11
|
+
@choices = []
|
12
|
+
@default = nil
|
13
|
+
@boolean = false
|
14
|
+
@envdefault = nil
|
15
|
+
unless options.nil?
|
16
|
+
meth = "parse_#{options.class.name.downcase}".to_sym
|
17
|
+
if respond_to? meth
|
18
|
+
send(meth, options)
|
19
|
+
else
|
20
|
+
fail OptionException, "Undefined parser ::#{meth}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_hash(args)
|
26
|
+
@choices = args[:choices] || args['choices'] || []
|
27
|
+
parse_array @choices
|
28
|
+
if args[:default] == false || args['default'] == false
|
29
|
+
@default ||= false
|
30
|
+
else
|
31
|
+
@default ||= args[:default] || args['default']
|
32
|
+
end
|
33
|
+
@boolean = args[:boolean] || args['boolean']
|
34
|
+
@default = true if (@boolean && @default.nil?)
|
35
|
+
@envdefault = args[:env] || args['env']
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_array(args)
|
39
|
+
@choices = args.map do |a|
|
40
|
+
if a[0] && a[0] == '='
|
41
|
+
@default = a[1..-1]
|
42
|
+
else
|
43
|
+
a
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_string(arg)
|
49
|
+
if arg.downcase.match /^y(es)?(\/)?n(o)?/
|
50
|
+
@boolean = true
|
51
|
+
if /y(es)?(\/)?N/.match arg
|
52
|
+
@default = false
|
53
|
+
else
|
54
|
+
@default = true
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@default = arg
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def boolean?
|
62
|
+
@boolean
|
63
|
+
end
|
64
|
+
|
65
|
+
def display
|
66
|
+
back = ''
|
67
|
+
if @boolean
|
68
|
+
back = @default ? "[Y/n]" : "[y/N]"
|
69
|
+
else
|
70
|
+
if @choices.count > 0
|
71
|
+
back += "(#{@choices.join(' / ')})"
|
72
|
+
end
|
73
|
+
back += "[#{@default}]" if @default
|
74
|
+
end
|
75
|
+
return back
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
data/lib/cliprompt.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "dye"
|
2
|
+
|
3
|
+
require "cliprompt/version"
|
4
|
+
require "cliprompt/optionset"
|
5
|
+
|
6
|
+
module Cliprompt
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
CUSTOM_STYLES = {
|
11
|
+
error: [ :bold, :red ],
|
12
|
+
ok: [ :bold, :green ]
|
13
|
+
}
|
14
|
+
define_dye_method CUSTOM_STYLES
|
15
|
+
|
16
|
+
MSG_MANDATORY_TEXT = Dye.dye("Sorry you need to fill that information.", [ :bold, :red ])
|
17
|
+
MSG_YES_OR_NO = Dye.dye("You need to answer by yes, no, y or n.", [ :bold, :red ])
|
18
|
+
MSG_CHOSE_IN_LIST = Dye.dye("You need to chose between the available options.", [ :bold, :red ])
|
19
|
+
|
20
|
+
def ask(question, *options)
|
21
|
+
if options[0].class == Optionset
|
22
|
+
opts = options[0]
|
23
|
+
else
|
24
|
+
opts = Optionset.new *options
|
25
|
+
end
|
26
|
+
output.print "#{question} #{opts.display} "
|
27
|
+
answer = input.gets.chomp
|
28
|
+
output.flush
|
29
|
+
check(answer, question, opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
def check(answer, question, opts)
|
33
|
+
if answer == ''
|
34
|
+
if !opts.default.nil?
|
35
|
+
answer = opts.default
|
36
|
+
else
|
37
|
+
output.puts MSG_MANDATORY_TEXT
|
38
|
+
ask(question, opts)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
if opts.boolean
|
42
|
+
if /^(y(es)?|n(o)?)$/.match(answer.downcase)
|
43
|
+
answer = !/^y(es)?$/.match(answer.downcase).nil?
|
44
|
+
else
|
45
|
+
output.puts MSG_YES_OR_NO
|
46
|
+
ask(question, opts)
|
47
|
+
end
|
48
|
+
elsif opts.choices.count > 0 && !opts.choices.include?(answer)
|
49
|
+
output.puts MSG_CHOSE_IN_LIST
|
50
|
+
ask(question, opts)
|
51
|
+
else
|
52
|
+
answer
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def setio(input, output)
|
58
|
+
@@input = input
|
59
|
+
@@output = output
|
60
|
+
end
|
61
|
+
|
62
|
+
def input
|
63
|
+
@@input ||= STDIN
|
64
|
+
end
|
65
|
+
|
66
|
+
def output
|
67
|
+
@@output ||= STDOUT
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'cliprompt/optionset'
|
5
|
+
|
6
|
+
describe Cliprompt::Optionset do
|
7
|
+
|
8
|
+
describe '.parse_array' do
|
9
|
+
Given(:options) { ['xxx', 'yyy', 'zzz'] }
|
10
|
+
|
11
|
+
context "when there is no default (#{['xxx', 'yyy', 'zzz'].to_s})," do
|
12
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
13
|
+
When(:choices) { set.choices }
|
14
|
+
When(:default) { set.default }
|
15
|
+
When(:display) { set.display }
|
16
|
+
Then { expect(choices).to eq options }
|
17
|
+
Then { expect(default).to be_false }
|
18
|
+
Then { expect(display).to eq "(xxx / yyy / zzz)" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when there is a default specified (#{['xxx', '=yyy', 'zzz'].to_s})," do
|
22
|
+
Given(:options_with_default) { ['xxx', '=yyy', 'zzz'] }
|
23
|
+
Given(:set) { Cliprompt::Optionset.new(options_with_default) }
|
24
|
+
When(:choices) { set.choices }
|
25
|
+
When(:default) { set.default }
|
26
|
+
When(:display) { set.display }
|
27
|
+
Then { expect(choices).to eq options }
|
28
|
+
Then { expect(default).to eq 'yyy' }
|
29
|
+
Then { expect(display).to eq "(xxx / yyy / zzz)[yyy]" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.parse_hash' do
|
34
|
+
|
35
|
+
context "when there is choices and default," do
|
36
|
+
context "when using sym keys (#{{ default: 'xxx', choices: ['xxx', 'yyy', 'zzz'] }.to_s})," do
|
37
|
+
Given(:options) { { default: 'xxx', choices: ['xxx', 'yyy', 'zzz'] } }
|
38
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
39
|
+
When(:choices) { set.choices }
|
40
|
+
When(:default) { set.default }
|
41
|
+
When(:display) { set.display }
|
42
|
+
Then { expect(choices).to eq ['xxx', 'yyy', 'zzz'] }
|
43
|
+
Then { expect(default).to eq 'xxx' }
|
44
|
+
Then { expect(display).to eq "(xxx / yyy / zzz)[xxx]" }
|
45
|
+
end
|
46
|
+
context "when using string keys (#{{ 'default' => 'xxx', 'choices' => ['xxx', 'yyy', 'zzz'] }.to_s})," do
|
47
|
+
Given(:options) { { 'default' => 'xxx', 'choices' => ['xxx', 'yyy', 'zzz'] } }
|
48
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
49
|
+
When(:choices) { set.choices }
|
50
|
+
When(:default) { set.default }
|
51
|
+
When(:display) { set.display }
|
52
|
+
Then { expect(choices).to eq ['xxx', 'yyy', 'zzz'] }
|
53
|
+
Then { expect(default).to eq 'xxx' }
|
54
|
+
Then { expect(display).to eq "(xxx / yyy / zzz)[xxx]" }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when there is only boolean," do
|
59
|
+
context "when no default is given, default booean is Y," do
|
60
|
+
Given(:options) { { boolean: true } }
|
61
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
62
|
+
When(:default) { set.default }
|
63
|
+
When(:display) { set.display }
|
64
|
+
When(:boolean) { set.boolean }
|
65
|
+
Then { expect(default).to be_true }
|
66
|
+
Then { expect(boolean).to be_true }
|
67
|
+
Then { expect(display).to eq "[Y/n]" }
|
68
|
+
end
|
69
|
+
context "when default is given as true, default booean is Y," do
|
70
|
+
Given(:options) { { boolean: true, default: true } }
|
71
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
72
|
+
When(:default) { set.default }
|
73
|
+
When(:display) { set.display }
|
74
|
+
When(:boolean) { set.boolean }
|
75
|
+
Then { expect(default).to be_true }
|
76
|
+
Then { expect(boolean).to be_true }
|
77
|
+
Then { expect(display).to eq "[Y/n]" }
|
78
|
+
end
|
79
|
+
context "when default is given as false, default boolean is N," do
|
80
|
+
Given(:options) { { boolean: true, default: false } }
|
81
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
82
|
+
When(:default) { set.default }
|
83
|
+
When(:display) { set.display }
|
84
|
+
When(:boolean) { set.boolean }
|
85
|
+
Then { expect(default).to be_false }
|
86
|
+
Then { expect(boolean).to be_true }
|
87
|
+
Then { expect(display).to eq "[y/N]" }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '.parse_string' do
|
93
|
+
|
94
|
+
context 'when a "yesno" kind of string is passed,' do
|
95
|
+
context 'when using yesno,' do
|
96
|
+
Given(:options) { 'yesno' }
|
97
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
98
|
+
When(:default) { set.default }
|
99
|
+
When(:display) { set.display }
|
100
|
+
When(:boolean) { set.boolean }
|
101
|
+
Then { expect(default).to be_true }
|
102
|
+
Then { expect(boolean).to be_true }
|
103
|
+
Then { expect(display).to eq "[Y/n]" }
|
104
|
+
end
|
105
|
+
context "when using yn," do
|
106
|
+
Given(:options) { 'yn' }
|
107
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
108
|
+
When(:default) { set.default }
|
109
|
+
When(:display) { set.display }
|
110
|
+
Then { expect(default).to be_true }
|
111
|
+
Then { expect(display).to eq "[Y/n]" }
|
112
|
+
end
|
113
|
+
context "when using YN," do
|
114
|
+
Given(:options) { 'YN' }
|
115
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
116
|
+
When(:default) { set.default }
|
117
|
+
When(:display) { set.display }
|
118
|
+
Then { expect(default).to be_true }
|
119
|
+
Then { expect(display).to eq "[Y/n]" }
|
120
|
+
end
|
121
|
+
context "when using yesNo," do
|
122
|
+
Given(:options) { 'yesNo' }
|
123
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
124
|
+
When(:default) { set.default }
|
125
|
+
When(:display) { set.display }
|
126
|
+
Then { expect(default).to be_false }
|
127
|
+
Then { expect(display).to eq "[y/N]" }
|
128
|
+
end
|
129
|
+
context "when using yN," do
|
130
|
+
Given(:options) { 'yesNo' }
|
131
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
132
|
+
When(:default) { set.default }
|
133
|
+
When(:display) { set.display }
|
134
|
+
Then { expect(default).to be_false }
|
135
|
+
Then { expect(display).to eq "[y/N]" }
|
136
|
+
end
|
137
|
+
context "when using y/N," do
|
138
|
+
Given(:options) { 'yesNo' }
|
139
|
+
Given(:set) { Cliprompt::Optionset.new(options) }
|
140
|
+
When(:default) { set.default }
|
141
|
+
When(:display) { set.display }
|
142
|
+
Then { expect(default).to be_false }
|
143
|
+
Then { expect(display).to eq "[y/N]" }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'cliprompt'
|
5
|
+
|
6
|
+
describe Cliprompt do
|
7
|
+
|
8
|
+
describe '.ask' do
|
9
|
+
Given(:input) { StringIO.new }
|
10
|
+
Given(:output) { StringIO.new }
|
11
|
+
Given { subject.setio(input, output) }
|
12
|
+
|
13
|
+
# context 'when it is free form,' do
|
14
|
+
# When(:question) { 'wazza?' }
|
15
|
+
# context 'without default,' do
|
16
|
+
# When(:args) { }
|
17
|
+
# When { subject.input.stub(:gets).and_return("\n") }
|
18
|
+
# When { subject.ask(question, args) }
|
19
|
+
# Then { expect(output).to receive(:print).with("#{question} ") }
|
20
|
+
# context 'when enter key is used,' do
|
21
|
+
# When(:answer) { subject.ask(question) }
|
22
|
+
# When { input.gets("\n") }
|
23
|
+
# Then { expect(output).to receive(:puts).with(Cliprompt::MSG_MANDATORY_TEXT)}
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# it 'is displayed ay the end of the question' do
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
context 'when there is no preset choices,' do
|
30
|
+
it 'only displays the question' do
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'when enter is typed,' do
|
34
|
+
it 'returns the default value' do
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'when a value is provided' do
|
38
|
+
it 'returns the value' do
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require 'rspec/given'
|
5
|
+
|
6
|
+
if ENV['COV']
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.profiles.define :hpcli do
|
9
|
+
add_filter '/vendor/'
|
10
|
+
add_filter '/spec/'
|
11
|
+
end
|
12
|
+
SimpleCov.start :hpcli
|
13
|
+
else
|
14
|
+
# require 'coveralls'
|
15
|
+
# Coveralls.wear!
|
16
|
+
|
17
|
+
require "codeclimate-test-reporter"
|
18
|
+
CodeClimate::TestReporter.start
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.mock_with :rspec
|
23
|
+
config.expect_with :rspec do |c|
|
24
|
+
c.syntax = :expect
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cliprompt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mose
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dye
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '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'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-given
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: This library provides a simple DSL for managing user interaction in a
|
112
|
+
CLI application.
|
113
|
+
email:
|
114
|
+
- mose@mose.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".coveralls.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".ruby-version"
|
123
|
+
- ".travis.yml"
|
124
|
+
- CHANGELOG.md
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- cliprompt.gemspec
|
130
|
+
- example.rb
|
131
|
+
- lib/cliprompt.rb
|
132
|
+
- lib/cliprompt/optionset.rb
|
133
|
+
- lib/cliprompt/version.rb
|
134
|
+
- spec/lib/cliprompt/optionset_spec.rb
|
135
|
+
- spec/lib/cliprompt_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
homepage: https://github.com/mose/cliprompt
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.2.2
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Env aware lib for CLI prompt.
|
161
|
+
test_files:
|
162
|
+
- spec/lib/cliprompt/optionset_spec.rb
|
163
|
+
- spec/lib/cliprompt_spec.rb
|
164
|
+
- spec/spec_helper.rb
|