easyprompt.rb

Path: easyprompt.rb
Last Update: Wed Sep 14 21:46:04 EDT 2005

EasyPrompt is a utility for command-line scripts. It handles prompts and default values, and also provides a testing facility for mocking out the command-line user.

For example, here’s an irb session that illustrates what EasyPrompt does:

  irb(main):001:0> require 'easyprompt'
  => true
  irb(main):002:0> prompt = EasyPrompt.new
  => #<EasyPrompt:0x5a42a0 @stdout=#<EasyPrompt::MockableStdout:0x5a3e04>>
  irb(main):003:0> fname = prompt.ask( "What's your first name?" )
  What's your first name? John
  => "John"
  irb(main):004:0> lname = prompt.ask( "What's your last name?", "Doe" )
  What's your last name? [Doe]
  => "Doe"
  irb(main):005:0> correct = prompt.ask( "Is your name #{ fname } #{ lname }?", true, :boolean )
  Is your name John Doe? [y]
  => true

In the first example, we ask for the user’s first name and get "John" as the response. In the second example, we supply the default of "Doe", which the user chooses by just pressing the "Enter" key. In the third example, we supply the default of true, which the user chooses as well. We received the boolean value true as opposed to the string "true" or "y", because we specified :boolean as the response_class.

The Rubyforge project page can be found at rubyforge.org/projects/easyprompt/ .

Required files

contxtlservice   observer  

[Validate]