piotrmurach / tty-prompt

A beautiful and powerful interactive command line prompt
https://ttytoolkit.org
MIT License
1.47k stars 136 forks source link

Emprovement #24

Closed vptcnt closed 7 years ago

vptcnt commented 8 years ago

Hi,

When I code this question,

prompt.ask('Folder name?') do |q| q.required true q.validate ->(v) { return !Dir.exist?(v) } q.messages[:valid?] = 'Folder already exists!' end

If I press directly [return], the required validation is not used ... and the validate lamba is directly processing.

To correct it , I have to write
prompt.ask('Folder name?') do |q| # q.required true q.validate ->(v) { return !v.nil? && !Dir.exist?(v) } q.messages[:valid?] = 'Folder already exists!' end

It would be great if the required method was taking account.

piotrmurach commented 8 years ago

Hey, thanks for using the library. Good catch. Do you fancy submitting PR?

piotrmurach commented 7 years ago

This has been added, you can now do

prompt.ask('Folder name?') do |q|
  q.required true
  q.validate ->(v) { !Dir.exist?(v) }
  q.messages[:required?] = 'Folder name cannot be empty!'
  q.messages[:valid?] = 'Folder already exists!'
end

I will release patch shortly.