Passing multiple arguments to Cap

67 views
Skip to first unread message

Adam Salter

unread,
Sep 30, 2007, 3:14:06 AM9/30/07
to Capistrano
OK, Here's the problem...
I'm using Cap as a basic shell script replacement (I don't use SCM
etc) I like that it gives you descriptions and namespaces and such for
tasks, and it's all going swimmingly - except...
I'd like to be able to read the arguments off the command into an
array...

cap upload dir_a dir_b dir_c

I know that the capistrano multistage extension reads several items
from the command line, so it should be possible.

If i just execute the above as is, I get a "task dir_a not
found" (although I can still use the arguments with ARGV[]).

TIA,
-Adam

Jamis Buck

unread,
Sep 30, 2007, 11:39:08 AM9/30/07
to capis...@googlegroups.com
Capistrano interprets all bare arguments as tasks to be executed. The
multistage extension makes this work by defining tasks for each
stage, so that "cap production deploy" first calls the "production"
task, and then calls "deploy".

If you want to pass parameters to your tasks, you can do it via
environment variables:

cap upload FILES=dir_a,dir_b,dir_c

Then, your upload task gets the FILES env var, parses it, and
processes the directories as needed:

task :upload do
files = ENV['FILES'].split(/,/)
# ...
end

- Jamis

> --~--~---------~--~----~------------~-------~--~----~
> To unsubscribe from this group, send email to capistrano-
> unsub...@googlegroups.com
> For more options, visit this group at http://groups.google.com/
> group/capistrano
> -~----------~----~----~----~------~----~------~--~---
>

Adam Salter

unread,
Oct 1, 2007, 1:37:56 AM10/1/07
to capis...@googlegroups.com
Ok. I guess that will have to do (not much choice :).

Seems like a workable solution

what might be nice, just thinking about it would be something like:

cap upload(dir_a, dir_b, dir_c)

I know cap depends on rake (and I think i'm in the minority) but
still a thought.

this would also allow

cap deploy(production)

Jamis Buck

unread,
Oct 1, 2007, 6:22:44 AM10/1/07
to capis...@googlegroups.com
Adam,

I know Rake has added support for parameterized tasks in the last
year or so. Capistrano doesn't reuse any of Rake's code, but perhaps
it's implementation of the feature might prove inspirational. As
ever, if you want something bad enough, the quickest way to see it
find its way into capistrano is via a patch.

- Jamis

Adam Salter

unread,
Oct 1, 2007, 8:37:16 AM10/1/07
to capis...@googlegroups.com
I'm actually in a position where I should be able to "justify" this
time :)

I'm confused that Capistrano doesn't use any of Rake's code as they
seem so close in many ways. I thought Cap was just an extended Rake.
No matter either way of course :)

I'll raise a ticket in the next few days.

Cheers,
-Adam

Jamis Buck

unread,
Oct 1, 2007, 11:03:37 AM10/1/07
to capis...@googlegroups.com
"Just an extended Rake."

Ouch. Pardon me while I extract this dagger from my heart. ;)

- Jamis

Adam Salter

unread,
Oct 1, 2007, 11:29:13 AM10/1/07
to capis...@googlegroups.com
Don't worry I'm an old hand at this... I've even got a "Patent
Pending" Dagger Extraction Kit.

There see? Good as new.

Now to erase all evidence... this is always the hard part... where
was my Google Trace Removal Kit...

Adam Salter

unread,
Oct 22, 2007, 9:01:52 PM10/22/07
to Capistrano
I have raised ticket #9447
http://dev.rubyonrails.org/ticket/9947

As you will see on the ticket I'm not sure how to continue. Any
feedback welcome.

> >>> Capistrano interprets all bareargumentsas tasks to be executed.


> >>> The multistage extension makes this work by defining tasks for each
> >>> stage, so that "cap production deploy" first calls the "production"
> >>>task, and then calls "deploy".
>
> >>> If you want to pass parameters to your tasks, you can do it via
> >>> environment variables:
>
> >>> cap upload FILES=dir_a,dir_b,dir_c
>

> >>> Then, your uploadtaskgets the FILES env var, parses it, and


> >>> processes the directories as needed:
>
> >>> task:upload do
> >>> files = ENV['FILES'].split(/,/)
> >>> # ...
> >>> end
>
> >>> - Jamis
>
> >>> On Sep 30, 2007, at 1:14 AM, Adam Salter wrote:
>
> >>>> OK, Here's the problem...
> >>>> I'm using Cap as a basic shell script replacement (I don't use SCM
> >>>> etc) I like that it gives you descriptions and namespaces and such
> >>>> for
> >>>> tasks, and it's all going swimmingly - except...

> >>>> I'd like to be able to read theargumentsoff the command into an


> >>>> array...
>
> >>>> cap upload dir_a dir_b dir_c
>
> >>>> I know that the capistrano multistage extension reads several items
> >>>> from the command line, so it should be possible.
>

> >>>> If i just execute the above as is, I get a "taskdir_a not

Reply all
Reply to author
Forward
0 new messages