inquirer.rb 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f63e9bf358de3b79f5c60ccad3b272a6d7dc80d
4
+ data.tar.gz: d09700b350451f94f2961a7d327c9b59b7fdcd42
5
+ SHA512:
6
+ metadata.gz: 6c7de1dd06980bed7ccd599ad8554352a152b5b46959020211f04693f9fad08a8799d77c4c0191b9939a97b66f044aa40ddddd5bc28618bda15a68053968692d
7
+ data.tar.gz: 9e10b66b41f0f913ba9594d98bca9b313875df9ca32061a2a8f4f4368d42b65f5588a40188712796bc8260f65696bffb11f522710208c050f131ee2f8f6e405f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at te@znuny.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inquirer.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Thorsten Eckel
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,197 @@
1
+ # Inquirer
2
+
3
+ A collection of common interactive command line user interfaces. A (not yet compleded) clone of the great [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) and strongly inspired by the similar [inquirer.rb](https://github.com/arlimus/inquirer.rb).
4
+
5
+ Started as a fork of [inquirer.rb](https://github.com/arlimus/inquirer.rb) the changes become to fundamental to keep it that way.
6
+
7
+ ## Goals
8
+
9
+ - [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) API conform as possible
10
+ - Extended functionality API similar as possible
11
+ - Slim dependencies
12
+ - Easy integration
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'inquirer'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install inquirer
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ require 'inquirer'
34
+
35
+ questions = [
36
+ {
37
+ name: :user_name,
38
+ type: :input, # optional - default ':input', others see below
39
+ message: 'What is your name?',
40
+ }
41
+ ]
42
+
43
+ answers = Inquirer.prompt(questions)
44
+
45
+ p answers[:user_name]
46
+
47
+ # => Tyler
48
+ ```
49
+
50
+ See the `examples` folder for more examples.
51
+
52
+ Basically it's:
53
+ - `Inquirer.prompt` takes an Array as parameter, containing question Hashes
54
+ - Each question Hash has to contain the parameters required for the given `:type` parameter
55
+ - If no `:type` paramter is given `:input` is used as default
56
+ - `Inquirer.prompt` returns a Hash with the question `:name` parameter as key and the user input as value
57
+
58
+ ### Prompt types
59
+
60
+ There parameters are valid for all prompt types:
61
+
62
+ - `:message` (String) The question to print.
63
+ - `:filter` (Proc) (optional) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the answers Hash.
64
+ - `:when` (Proc|Boolean) (optional) Receive the current user answers Hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
65
+
66
+ #### Input (`type: :input`)
67
+
68
+ ![:input](screenshots/input.png ":input")
69
+
70
+ - `:default` (String) (optional) Default value to use if nothing is entered.
71
+ - `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
72
+
73
+ #### Password (`type: :password`)
74
+
75
+ ![:password](screenshots/password.png ":password")
76
+
77
+ - `:default` (String) (optional) Default value to use if nothing is entered.
78
+ - `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
79
+
80
+ #### List (`type: :list`)
81
+
82
+ ![:list](screenshots/list.png ":list")
83
+
84
+ - `:choices` (Array) Has to contain Hashes with the following parameters:
85
+ - `:name` (String) The display value
86
+ - `:short` (String) (optional) To display after selection
87
+ - `:value` (String|Symbol) To save in the answers Hash
88
+ - `:default` (Integer|String|Symbol) (optional) Must be the choice index (Integer) in the Array or a choice `:value` parameters value (String|Symbol).
89
+
90
+ #### Checkbox (`type: :checkbox`)
91
+
92
+ ![:checkbox](screenshots/checkbox.png ":checkbox")
93
+
94
+ - `:choices` (Array) Has to contain Hashes with the following parameters:
95
+ - `:name` (String) The display value
96
+ - `:short` (String) (optional) To display after selection
97
+ - `:value` (String|Symbol) To save in the answers Hash
98
+ - `:checked` (Boolean) (optional) True choices will be checked by default
99
+ - `:default` (Array) (optional) An Array of choices `:value` parameters values (String|Symbol).
100
+ - `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
101
+
102
+ #### Confirm (`type: :confirm`)
103
+
104
+ ![:confirm](screenshots/confirm.png ":confirm")
105
+
106
+ - `:default` (Boolean) (optional) Default value to use if nothing is entered is expected to be a boolean.
107
+
108
+ ## Development
109
+
110
+ ### General
111
+
112
+ - [x] `:type` parameter (InquirerJS conform)
113
+ - [x] no `:type` parameter provided results in `:input` (InquirerJS conform)
114
+ - [x] `:name` parameter (InquirerJS conform)
115
+ - [x] `:message` (String) parameter (InquirerJS conform)
116
+ - [ ] `:message` (Proc) parameter (InquirerJS conform)
117
+ - [x] `:default` (String) parameter (optional) (InquirerJS conform)
118
+ - [ ] `:default` (Proc) parameter (optional) (InquirerJS conform)
119
+ - [x] `:when` (Proc) parameter (optional) (InquirerJS conform)
120
+ - [x] `:when` (Boolean) parameter (optional) (InquirerJS conform)
121
+ - [x] `:filter` (Proc) parameter (optional)
122
+ - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
123
+ - [x] colored formatting (InquirerJS conform)
124
+ - [x] easy styling / formatting of all output components (question, result, items, password....)
125
+
126
+ ### Input
127
+
128
+ - [x] Backend
129
+ - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
130
+ - [ ] Tests
131
+
132
+ ### Password
133
+
134
+ - [x] Backend
135
+ - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
136
+ - [ ] Tests
137
+
138
+ ### List
139
+
140
+ - [x] Backend
141
+ - [x] `:choices` (Array) parameter (InquirerJS conform)
142
+ - [ ] `:choices` (Proc) parameter (InquirerJS conform)
143
+ - [x] `:choices` `:name` parameter (InquirerJS conform)
144
+ - [x] `:choices` `:value` parameter (InquirerJS conform)
145
+ - [x] `:choices` `:short` parameter (InquirerJS conform)
146
+ - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
147
+ - [ ] Tests
148
+
149
+ ### Checkbox
150
+
151
+ - [x] Backend
152
+ - [x] `:choices` (Array) parameter (InquirerJS conform)
153
+ - [ ] `:choices` (Proc) parameter (InquirerJS conform)
154
+ - [x] `:choices` `:name` parameter (InquirerJS conform)
155
+ - [x] `:choices` `:value` parameter (InquirerJS conform)
156
+ - [x] `:choices` `:checked` parameter (InquirerJS conform)
157
+ - [ ] `:choices` `:disabled` (String) parameter (InquirerJS conform)
158
+ - [ ] `:choices` `:disabled` (Boolean) parameter (InquirerJS conform)
159
+ - [ ] `:choices` `:disabled` (Proc) parameter (InquirerJS conform)
160
+ - [x] `:choices` `:short` parameter
161
+ - [ ] Tests
162
+
163
+ ### Confirm
164
+
165
+ - [x] Backend
166
+ - [ ] Tests
167
+
168
+ ### Raw List
169
+
170
+ - [ ] Backend
171
+ - [ ] `:choices` parameter (InquirerJS conform)
172
+ - [ ] Tests
173
+
174
+ ### Expand
175
+
176
+ - [ ] Backend
177
+ - [ ] `:choices` parameter (InquirerJS conform)
178
+ - [ ] Tests
179
+
180
+ ### Seperator
181
+
182
+ - [ ] constructor takes a facultative String value that'll be use as the separator (InquirerJS conform)
183
+ - [ ] default separator `--------` (InquirerJS conform)
184
+ - [ ] Tests
185
+
186
+ ### BottomBar
187
+
188
+ - [ ] fixed text at the bottom of a free text zone (InquirerJS conform)
189
+ - [ ] Tests
190
+
191
+ ## Contributing
192
+
193
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thorsteneckel/inquirer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
194
+
195
+ ## License
196
+
197
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,203 @@
1
+ lib = File.expand_path('../../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'inquirer'
5
+
6
+ questions = [
7
+ {
8
+ name: :invitation,
9
+ type: :checkbox,
10
+ message: 'Who should get invited?',
11
+ choices: [
12
+ {
13
+ name: 'Karl',
14
+ short: 'Kalli',
15
+ },
16
+ {
17
+ name: 'Bert',
18
+ value: "It's Bert!"
19
+ },
20
+ {
21
+ name: 'Berta',
22
+ value: :love
23
+ },
24
+ {
25
+ name: 'Manfred',
26
+ },
27
+ ],
28
+ },
29
+ {
30
+ name: :invitation_default,
31
+ type: :checkbox,
32
+ message: 'Who should get invited?',
33
+ choices: [
34
+ {
35
+ name: 'Karl',
36
+ short: 'Kalli',
37
+ },
38
+ {
39
+ name: 'Bert',
40
+ value: "It's Bert!"
41
+ },
42
+ {
43
+ name: 'Berta',
44
+ value: :love
45
+ },
46
+ {
47
+ name: 'Manfred',
48
+ },
49
+ ],
50
+ default: [
51
+ "It's Bert!",
52
+ :love,
53
+ 'Manfred',
54
+ ],
55
+ },
56
+ {
57
+ name: :invitation_never,
58
+ type: :checkbox,
59
+ message: 'Who should get invited?',
60
+ choices: [
61
+ {
62
+ name: 'Karl',
63
+ short: 'Kalli',
64
+ },
65
+ {
66
+ name: 'Bert',
67
+ value: "It's Bert!"
68
+ },
69
+ {
70
+ name: 'Berta',
71
+ value: :love
72
+ },
73
+ {
74
+ name: 'Manfred',
75
+ },
76
+ ],
77
+ when: false,
78
+ },
79
+ {
80
+ name: :invitation_never_lambda,
81
+ type: :checkbox,
82
+ message: 'Who should get invited?',
83
+ choices: [
84
+ {
85
+ name: 'Karl',
86
+ short: 'Kalli',
87
+ },
88
+ {
89
+ name: 'Bert',
90
+ value: "It's Bert!"
91
+ },
92
+ {
93
+ name: 'Berta',
94
+ value: :love
95
+ },
96
+ {
97
+ name: 'Manfred',
98
+ },
99
+ ],
100
+ when: lambda { |answers| true },
101
+ },
102
+ {
103
+ name: :invitation_when_previous,
104
+ type: :checkbox,
105
+ message: 'Who should get invited?',
106
+ choices: [
107
+ {
108
+ name: 'Karl',
109
+ short: 'Kalli',
110
+ },
111
+ {
112
+ name: 'Bert',
113
+ value: "It's Bert!"
114
+ },
115
+ {
116
+ name: 'Berta',
117
+ value: :love
118
+ },
119
+ {
120
+ name: 'Manfred',
121
+ },
122
+ ],
123
+ when: lambda { |answers| answers[:invitation_default].size > 1 },
124
+ },
125
+ {
126
+ name: :invitation_validate_size,
127
+ type: :checkbox,
128
+ message: 'Who should get invited?',
129
+ choices: [
130
+ {
131
+ name: 'Karl',
132
+ short: 'Kalli',
133
+ },
134
+ {
135
+ name: 'Bert',
136
+ value: "It's Bert!"
137
+ },
138
+ {
139
+ name: 'Berta',
140
+ value: :love
141
+ },
142
+ {
143
+ name: 'Manfred',
144
+ },
145
+ ],
146
+ validate: lambda { |answer| answer.size == 2 },
147
+ },
148
+ {
149
+ name: :invitation_validate_tyler_message,
150
+ type: :checkbox,
151
+ message: 'Who should get invited?',
152
+ choices: [
153
+ {
154
+ name: 'Karl',
155
+ short: 'Kalli',
156
+ },
157
+ {
158
+ name: 'Bert',
159
+ value: "It's Bert!"
160
+ },
161
+ {
162
+ name: 'Berta',
163
+ value: :love
164
+ },
165
+ {
166
+ name: 'Manfred',
167
+ },
168
+ ],
169
+ validate: lambda { |answer|
170
+ return true if answer.include? 'Tyler'
171
+ 'Only Tyler!'
172
+ },
173
+ },
174
+ {
175
+ name: :invitation_filter_tyler,
176
+ type: :checkbox,
177
+ message: 'Who should get invited?',
178
+ choices: [
179
+ {
180
+ name: 'Karl',
181
+ short: 'Kalli',
182
+ },
183
+ {
184
+ name: 'Bert',
185
+ value: "It's Bert!"
186
+ },
187
+ {
188
+ name: 'Berta',
189
+ value: :love
190
+ },
191
+ {
192
+ name: 'Manfred',
193
+ },
194
+ ],
195
+ filter: lambda { |answer|
196
+ ['Tyler']
197
+ },
198
+ },
199
+ ]
200
+
201
+ answers = Inquirer.prompt(questions)
202
+
203
+ p answers