My thoughts exactly - I wonder if this should become a part of capistrano-ext ? - Lee
2009/3/12 S. Robert James <[email protected]> > > Great code - how 'bout wrapping it up as an extension? > > On Mar 10, 2:42 pm, andynu <[email protected]> wrote: > > I took a different approach. Since you have access to the ENV object I > > added a few helpers > > > > def menu(variable,options) > > Capistrano::CLI.ui.choose do |menu| > > options.each {|c| menu.choice(c)} > > menu.header = "( ? ) Select #{variable.to_s}" > > end > > end > > > > def env_or_menu(variable,options) > > value = if ENV[variable.to_s].nil? > > Capistrano::CLI.ui.choose do |menu| > > options.each {|c| menu.choice(c)} > > menu.header = "( ? ) Select #{variable.to_s}" > > end > > else > > if ENV[variable.to_s] == /^:/ > > ENV[variable.to_s].to_sym > > else > > ENV[variable.to_s].to_s > > end > > end > > yield(value) if block_given? > > return value > > end > > > > def env_or_ask(variable,question) > > value = if ENV[variable.to_s].nil? > > Capistrano::CLI.ui.ask(question) > > else > > if ENV[variable.to_s] == /^:/ > > ENV[variable.to_s].to_sym > > else > > ENV[variable.to_s].to_s > > end > > end > > yield(value) if block_given? > > return value > > end > > > > def env_or_set(variable,value) > > value = if ENV[variable.to_s].nil? > > value > > else > > if ENV[variable.to_s] == /^:/ > > ENV[variable.to_s].to_sym > > else > > ENV[variable.to_s].to_s > > end > > end > > yield(value) if block_given? > > return value > > end > > > > def set_ask_menu(variable,options) > > set(variable) do > > env_or_menu(variable,options) do |value| > > yield(value) if block_given? > > end > > end > > end > > > > def set_ask(variable,question) > > set(variable) do > > env_or_ask(variable,question) do |value| > > yield(value) if block_given? > > end > > end > > end > > > > With those you can do things like > > > > env_or_set(:some_variable, "some_default_value") > > > > if you provide it it'll use it, otherwise it'll use the default. > > e.g. > > > > cap task some_variable=custom_value > > > > or > > > > env_or_menu(:some_variable, ["option1","option2","option3"]) > > will take the environment or provide a menu. > > > > On Mar 8, 6:46 pm, "S. Robert James" <[email protected]> wrote: > > > > > > > > > Is there a standard Capistrano idiom for passing in, and parsing, user > > > defined parameters from the command line? I know vars can be set using > > > -S. But I'd like more: supporting boolean switches, or switches with > > > a default val. If I was writing my own script, I'd use OptionParser or > > > the like - what's the preferred Capistrano way to do this? > > > > > Along similar lines, is there a standard idiom for a task to take a > > > parameter, or return a result? I could hack this with a global > > > variable, but I'd like to find a preferred way. > > > --~--~---------~--~----~------------~-------~--~----~ To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/capistrano -~----------~----~----~----~------~----~------~--~---
