Created
April 22, 2013 18:40
-
-
Save torjusb/5437422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "highline/import" | |
class HighLine | |
alias_method :orig_ask, :ask | |
def ask(question, answer_type = String, &details) | |
question = "<%= color('#{question}', :green) %>: " | |
orig_ask(question, answer_type = String, &details) | |
end | |
class Question | |
def append_default | |
default = "[<%= color('#{@default}', :yellow) %>]" | |
if @question =~ /(.+):([\t ]+)\Z/ | |
@question = "#{$1} #{default}:#{$2}" | |
else | |
@question << default | |
end | |
end | |
end | |
end | |
site_name = HighLine.new.ask("Enter sitename") do |q| | |
q.validate = /[a-z_]/ | |
end | |
host_name = HighLine.new.ask("Enter hostname") do |q| | |
q.default="#{site_name}.no" | |
end | |
puts "Site name: #{site_name}, Host name: #{host_name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment