OK, sent it by mistake so here's the rest of the code

module EnvironmentOptions
 def var!
    mandatory('VAR')
 end
  def mandatory option
    ENV[option] || raise("Environment variable #{option} no set. required
for this task")
  end
end

Rake also has a way to define task arguments. You call the task with

cap stage task[arg1,arg2]

and then you define the task as

task :task :arg1 :arg2 do |t,args|
 p args
end

TBH I only use the environment variable passing option because it keeps my
task definitions cleaner and my parameters neatly documented and tucked
away in a module.

Cheers,
V.-

On Wed, Oct 16, 2013 at 10:22 PM, Vassilis Rizopoulos <
[email protected]> wrote:

> Well, the new Capistrano is based on rake so you have a few options.
> One is the use of environment variables. You can set the before hand or
> you can specify them on the command line:
>
> cap stage task VAR=foo
>
> Access in the code is through the ENV Hash:
>
> ENV['VAR']
>
> This is actually what I do and I do it the following way: I put accessor
> methods for environment variables in a module. This allows me to add code
> to check for definitions and make sure I warn the user if the parameter is
> really needed:
>
> module EnvironmentOptions
>   def var
>     return ENV['VAR']
>   end
>
>
> end
>
>
>

-- 
-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to [email protected]
* To unsubscribe from this group, send email to 
[email protected] For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to