tty-prompt 0.23.0 → 0.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +25 -4
- data/lib/tty/prompt/choice.rb +24 -7
- data/lib/tty/prompt/question/checks.rb +1 -1
- data/lib/tty/prompt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ced9f6a4234a7234fc2dbce1bc17a982afd2922d7a5c30e0f57030c0970e01
|
4
|
+
data.tar.gz: 26835914ed361e5617660f8bbd9106c101d2963a6e7ae335c4c57ed910658773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 767a3e943e5740eddbcf14fe9d25fd1d14054402c45d7020762b2cc78842720699223ec27fd229ea70cfb47ab6879b5fd144a76073e44092ed4b8eca1a56e357
|
7
|
+
data.tar.gz: 65b4c4d5ec2d06b900ef4bbd2012eb12c1c1952fe2b7c8ba1865714393da5c34f232a13a35bbefeee870b57d2cb741c77586725bd00a3a1e6a7a61521dfb8c13
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.23.1] - 2021-04-17
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change validate to allow access to invalid input inside the message
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
* Fix Choice#from to differentiate between no value being set and nil value
|
10
|
+
|
3
11
|
## [v0.23.0] - 2020-12-14
|
4
12
|
|
5
13
|
### Added
|
@@ -394,6 +402,7 @@
|
|
394
402
|
|
395
403
|
* Initial implementation and release
|
396
404
|
|
405
|
+
[v0.23.1]: https://github.com/piotrmurach/tty-prompt/compare/v0.23.0...v0.23.1
|
397
406
|
[v0.23.0]: https://github.com/piotrmurach/tty-prompt/compare/v0.22.0...v0.23.0
|
398
407
|
[v0.22.0]: https://github.com/piotrmurach/tty-prompt/compare/v0.21.0...v0.22.0
|
399
408
|
[v0.21.0]: https://github.com/piotrmurach/tty-prompt/compare/v0.20.0...v0.21.0
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -357,7 +357,7 @@ prompt.ask("password:", echo: false)
|
|
357
357
|
|
358
358
|
#### 2.1.5 error messages
|
359
359
|
|
360
|
-
By default `tty-prompt` comes with predefined error messages for `required`, `in`, `validate` options.
|
360
|
+
By default `tty-prompt` comes with predefined error messages for `convert`, `required`, `in`, `validate` options.
|
361
361
|
|
362
362
|
You can change these and configure to your liking either by passing message as second argument with the option:
|
363
363
|
|
@@ -367,7 +367,7 @@ prompt.ask("What is your email?") do |q|
|
|
367
367
|
end
|
368
368
|
```
|
369
369
|
|
370
|
-
Or change the `messages` key entry out of `:
|
370
|
+
Or change the `messages` key entry out of `:convert?`, `:range?`, `:required?` and `:valid?`:
|
371
371
|
|
372
372
|
```ruby
|
373
373
|
prompt.ask("What is your email?") do |q|
|
@@ -432,7 +432,9 @@ prompt.ask("What's your phone number?", required: true)
|
|
432
432
|
|
433
433
|
#### 2.1.9 `:validate`
|
434
434
|
|
435
|
-
In order to validate that input matches a given pattern you can pass the `validate` option.
|
435
|
+
In order to validate that input matches a given pattern you can pass the `validate` option/method.
|
436
|
+
|
437
|
+
Validate accepts `Regex`, `Proc` or `Symbol`.
|
436
438
|
|
437
439
|
```ruby
|
438
440
|
prompt.ask("What is your username?") do |q|
|
@@ -440,18 +442,37 @@ prompt.ask("What is your username?") do |q|
|
|
440
442
|
end
|
441
443
|
```
|
442
444
|
|
445
|
+
The above can also be expressed as a `Proc`:
|
446
|
+
|
443
447
|
```ruby
|
444
448
|
prompt.ask("What is your username?") do |q|
|
445
449
|
q.validate ->(input) { input =~ /\A[^.]+\.[^.]+\Z/ }
|
446
450
|
end
|
447
451
|
```
|
448
452
|
|
449
|
-
|
453
|
+
There is a built-in validation for `:email` and you can use it directly like so:
|
450
454
|
|
451
455
|
```ruby
|
452
456
|
prompt.ask("What is your email?") { |q| q.validate :email }
|
453
457
|
```
|
454
458
|
|
459
|
+
The default validation message is `"Your answer is invalid (must match %{valid})"` and you can customise it by passing in a second argument:
|
460
|
+
|
461
|
+
```ruby
|
462
|
+
prompt.ask("What is your username?") do |q|
|
463
|
+
q.validate(/\A[^.]+\.[^.]+\Z/, "Invalid username: %{value}, must match %{valid}")
|
464
|
+
end
|
465
|
+
```
|
466
|
+
|
467
|
+
The default message can also be set using `messages` and the `:valid?` key:
|
468
|
+
|
469
|
+
```ruby
|
470
|
+
prompt.ask("What is your username?") do |q|
|
471
|
+
q.validate(/\A[^.]+\.[^.]+\Z/)
|
472
|
+
q.messages[:valid?] = "Invalid username: %{value}, must match %{valid}")
|
473
|
+
end
|
474
|
+
```
|
475
|
+
|
455
476
|
### 2.2. keypress
|
456
477
|
|
457
478
|
In order to ask question that awaits a single character answer use `keypress` prompt like so:
|
data/lib/tty/prompt/choice.rb
CHANGED
@@ -31,12 +31,7 @@ module TTY
|
|
31
31
|
when Choice
|
32
32
|
val
|
33
33
|
when Array
|
34
|
-
|
35
|
-
if name.is_a?(Hash)
|
36
|
-
convert_hash(name)
|
37
|
-
else
|
38
|
-
new(name.to_s, (value.nil? ? name.to_s : value), **(options || {}))
|
39
|
-
end
|
34
|
+
convert_array(val)
|
40
35
|
when Hash
|
41
36
|
convert_hash(val)
|
42
37
|
else
|
@@ -44,7 +39,29 @@ module TTY
|
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
47
|
-
# Convert
|
42
|
+
# Convert an array into choice
|
43
|
+
#
|
44
|
+
# @param [Array<Object>]
|
45
|
+
#
|
46
|
+
# @return [Choice]
|
47
|
+
#
|
48
|
+
# @api public
|
49
|
+
def self.convert_array(val)
|
50
|
+
name, value, options = *val
|
51
|
+
if name.is_a?(Hash)
|
52
|
+
convert_hash(name)
|
53
|
+
elsif val.size == 1
|
54
|
+
new(name.to_s, name.to_s)
|
55
|
+
else
|
56
|
+
new(name.to_s, value, **(options || {}))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Convert a hash into choice
|
61
|
+
#
|
62
|
+
# @param [Hash<Symbol,Object>]
|
63
|
+
#
|
64
|
+
# @return [Choice]
|
48
65
|
#
|
49
66
|
# @api public
|
50
67
|
def self.convert_hash(val)
|
@@ -56,7 +56,7 @@ module TTY
|
|
56
56
|
Validation.new(question.validation).call(value))
|
57
57
|
[value]
|
58
58
|
else
|
59
|
-
tokens = { valid: question.validation.inspect }
|
59
|
+
tokens = { valid: question.validation.inspect, value: value }
|
60
60
|
[value, question.message_for(:valid?, tokens)]
|
61
61
|
end
|
62
62
|
end
|
data/lib/tty/prompt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-prompt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.
|
4
|
+
version: 0.23.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|