Skip to content

Instantly share code, notes, and snippets.

@torjusb
Created April 22, 2013 18:40
Show Gist options
  • Save torjusb/5437422 to your computer and use it in GitHub Desktop.
Save torjusb/5437422 to your computer and use it in GitHub Desktop.
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