cliprompt 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f310eea2a9640504286446d80f3fe6d22a65607
4
- data.tar.gz: 187a52dd0480192fe77571d0b937f8c2b4c66c4c
3
+ metadata.gz: ad8694ae5f71787a7a5e51c1451f7f15ce16abe4
4
+ data.tar.gz: 1e41e408ad7acf5c27c3e7e031e4ee142abd5c59
5
5
  SHA512:
6
- metadata.gz: e74304a82d4c37c39f3d5d2289cb8239635ec57738e4bf36d250745dcdb032ae8cd20494901fa8ad2870a01c4010678d0c9385968910574abf1b05b4f7a968cf
7
- data.tar.gz: 2b7acdb26a178e024213beac9a4be22f5e6f08f6ae5cbc7ebca69a9b781aa7fed84f198f8ca9947f70c6bac64da62ca14894371159f92a13aa909a6f369e5bda
6
+ metadata.gz: 1f66243c356834abe4dbb25e165496453121fd536e16d9f4ed3127618b2566a2f3d88f8d2a8cba76d1361b4a5b5bd02bf0c88c46395983b5b2115e60c666727b
7
+ data.tar.gz: 992a171945a441a158ebd2ec25863944a12620d8da79322838029b62c4fc065e46f0b34ca17320f62f4b206dc591ef64c717cbb49862d5d9de534d9ac4cd8c6a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Cliprompt Changelog
2
2
  =====================
3
3
 
4
+ v0.0.3 - 2014-05-20
5
+ -------------
6
+
7
+ - relax the boolean check so 1 and 0 can be used for yes and no (especially for env vars)
8
+ - added a `guess` method to have env var override question if set
9
+
4
10
  v0.0.2 - 2014-05-20
5
11
  -----------
6
12
 
data/README.md CHANGED
@@ -7,13 +7,13 @@ Cliprompt
7
7
  [![Dependency Status](https://gemnasium.com/mose/cliprompt.svg)](https://gemnasium.com/mose/cliprompt)
8
8
  [![Code Climate](https://codeclimate.com/github/mose/cliprompt.png)](https://codeclimate.com/github/mose/cliprompt)
9
9
 
10
- This library provides a simple DSL for managing user interaction in a CLI application. Still under development, not stable yet.
10
+ This library provides a simple DSL for managing user interaction in a CLI application. Still under development, not stable yet. Check the [Changelog](https://github.com/mose/cliprompt/blob/master/CHANGELOG.md) to see what is in already.
11
11
 
12
12
  Features
13
13
  ----------
14
14
 
15
15
  - manages questions, choices, default values, yes/no values (done)
16
- - makes possible to have env vars set for defaults (todo)
16
+ - makes possible to have env vars set for defaults (done)
17
17
 
18
18
  Usage
19
19
  ----------
@@ -33,6 +33,9 @@ class Myclass
33
33
  @url = ask "What is the url of Myclass?"
34
34
  @ssl = ask "Is it using SSL?", 'y/N'
35
35
  @age = ask "What is the age of the captain?", [22,33,=44,55]
36
+ # if you set set ENV['SOMEVAR'], it will override the answer and won't display the question
37
+ # in such case you still can use normal options and nev var will be validated against it (for boolean or choices setup)
38
+ @age = guess 'SOMEVAR', "What is the age of the captain?", [22,33,=44,55]
36
39
  end
37
40
  end
38
41
  ```
data/example.rb CHANGED
@@ -32,12 +32,28 @@ class Myclass
32
32
  show 'a list with default?', choices: ['22', 33, '=44', '55']
33
33
  end
34
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
+
35
43
  def show(*args)
36
44
  it = ask *args
37
45
  puts "-- returned #{it.inspect}"
38
46
  puts
39
47
  end
48
+
49
+ def showguess(*args)
50
+ it = guess *args
51
+ puts "-- returned #{it.inspect}"
52
+ puts
53
+ end
54
+
40
55
  end
41
56
 
42
57
  m = Myclass.new
58
+ m.guessit
43
59
  m.askit
@@ -56,7 +56,7 @@ module Cliprompt
56
56
  end
57
57
 
58
58
  def parse_string(arg)
59
- if arg.downcase.match /^y(es)?(\/)?n(o)?/
59
+ if arg.match /^[yY1](es)?(\/)?[nN0](o)?/
60
60
  @boolean = true
61
61
  if /y(es)?(\/)?N/.match arg
62
62
  @default = false
@@ -99,9 +99,8 @@ module Cliprompt
99
99
  end
100
100
 
101
101
  def check_boolean(question, answer)
102
- answer.downcase!
103
- return ask_again(question, Cliprompt::MSG_YES_OR_NO) unless /^(y(es)?|n(o)?)$/.match(answer)
104
- !/^y(es)?$/.match(answer).nil?
102
+ return ask_again(question, Cliprompt::MSG_YES_OR_NO) unless /^([yY1](es)?|[nN0](o)?)$/.match(answer)
103
+ !/^[yY1](es)?$/.match(answer).nil?
105
104
  end
106
105
 
107
106
  def check_choices(question, answer)
@@ -1,3 +1,3 @@
1
1
  module Cliprompt
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cliprompt.rb CHANGED
@@ -8,7 +8,7 @@ module Cliprompt
8
8
  module_function
9
9
 
10
10
  MSG_MANDATORY_TEXT = "Sorry you need to fill that information."
11
- MSG_YES_OR_NO = "You need to answer by yes, no, y or n."
11
+ MSG_YES_OR_NO = "You need to answer by yes, no, y, n, 1 or 0."
12
12
  MSG_CHOSE_IN_LIST = "You need to chose between the available options."
13
13
 
14
14
  def ask(question, *options)
@@ -23,6 +23,15 @@ module Cliprompt
23
23
  opts.validate(question, answer)
24
24
  end
25
25
 
26
+ def guess(env, question, *options)
27
+ opts = Optionset.new *options
28
+ if ENV[env]
29
+ opts.validate(question, ENV[env])
30
+ else
31
+ ask question, opts
32
+ end
33
+ end
34
+
26
35
  def say(message)
27
36
  output.puts message
28
37
  end
@@ -33,6 +33,24 @@ describe Cliprompt do
33
33
  end
34
34
  end
35
35
 
36
+ describe '.guess' do
37
+ Given(:question) { 'wazza?' }
38
+ Given(:env_var) { 'SOMEVAR' }
39
+ Given(:args) { }
40
+ context 'when env var is provided,' do
41
+ When(:env_value) { 'xxx' }
42
+ When { ENV[env_var] = env_value }
43
+ Then { expect(subject.guess(env_var, question, args)).to eq env_value }
44
+ And { ENV.delete(env_var) }
45
+ end
46
+ context 'when env var is not provided,' do
47
+ When(:answer) { 'ooo' }
48
+ When { input.stub(:gets).and_return answer }
49
+ Then { expect(subject.guess(env_var, question, args)).to eq answer }
50
+ And { expect(output.string).to eq "#{question} " }
51
+ end
52
+ end
53
+
36
54
  describe '.say' do
37
55
  Given(:msg) { "hah" }
38
56
  When { subject.say msg }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliprompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose