Ok, this is some code I found while hunting for a good way to prompt
for a release number to use when checking out tags from subversion.
This gives the option of setting the variable with -S or letting it
prompt you and the "ask" method is definitely reusable.

Just thought everyone might want to check it out, since it was
somewhat difficult for me to find on google.

<snip>

desc "Development Environment Initialization"
task :development do
  # Other variables set here but not pertinent to example
  # Other roles set here but not pertinent to example
  set :release_tag, ""
  set_release_tag
end

task :set_release_tag do
  ask(:release_tag, "  What release do you wish to use?")
end

# if key is not set at cmdline via -S, asks for it!
def ask(key, question, default=nil)
    if self[key].nil?
        if question =~ /password|passwd/i
            set key, Capistrano::CLI.password_prompt("#{question}
(#{default.to_s}): ")
        else
            printf "#{question} (#{default.to_s}): "; STDOUT.flush
            set key, STDIN.readline.chomp
        end
        if self[key] == "" and not default.nil?
            self[key] = default
        end
    end
end

</snip>

I'd like to give the credit to choonkeat.  What looks like his blog is
http://blog.yanime.org/

I found this snippet by following comment number 4 on at this url.
http://drnicwilliams.com/2007/04/10/capistrano-variables/

The choonkeat's code can be found http://pastie.caboo.se/52993 and I'm
posting my implementation of it here for discussion.

-prpht9


--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to