PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > rake task with arguments
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
rake task with arguments

Réponse
 
LinkBack Outils de la discussion
Vieux 25/02/2008, 20h39   #1
Reacher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut rake task with arguments

I found an example (http://www.betweentherails.com/rake/) of passing
arguments to a rake task in the new (0.8.n) version of rake. From this
example, I created the following test:

namespace :foo do
desc 'lol'
task :bar, :num do |t, args|
puts "num = #{args.num}"
end
end

I took a look at the task list:

$ rake --tasks
(in /path/to/my/dir)
rake foo:bar[num] # lol

All looks well ... until I try to run it:

$ rake foo:bar[123]
rake: No match

Hmm .. let's try without the argument:

$ rake foo:bar
(in /path/to/my/dir)
num =

o.O
  Réponse avec citation
Vieux 25/02/2008, 20h40   #2
Reacher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

On Feb 25, 2:39pm, Reacher <brandon.g.jo...@gmail.com> wrote:
> I found an example (http://www.betweentherails.com/rake/) of passing
> arguments to a rake task in the new (0.8.n) version of rake. From this
> example, I created the following test:
>
> namespace :foo do
> desc 'lol'
> task :bar, :num do |t, args|
> puts "num = #{args.num}"
> end
> end
>
> I took a look at the task list:
>
> $ rake --tasks
> (in /path/to/my/dir)
> rake foo:bar[num] # lol
>
> All looks well ... until I try to run it:
>
> $ rake foo:bar[123]
> rake: No match
>
> Hmm .. let's try without the argument:
>
> $ rake foo:bar
> (in /path/to/my/dir)
> num =
>
> o.O


I figured it out

$ rake foo:bar\[123\]
(in /path/to/my/dir)
num = 123

BTW, csh is evil
  Réponse avec citation
Vieux 25/02/2008, 20h49   #3
Jos Backus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

On Tue, Feb 26, 2008 at 05:39:57AM +0900, Reacher wrote:
> All looks well ... until I try to run it:
>
> $ rake foo:bar[123]
> rake: No match


Try this instead:

$ rake 'foo:bar[123]'

The shell is interpreting the []'s as globbing metacharacters. You have to
quote them so the shell passes them to ruby as-is.

--
Jos Backus
jos at catnook.com

  Réponse avec citation
Vieux 25/02/2008, 21h07   #4
Joel VanderWerf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

Jos Backus wrote:
> On Tue, Feb 26, 2008 at 05:39:57AM +0900, Reacher wrote:
>> All looks well ... until I try to run it:
>>
>> $ rake foo:bar[123]
>> rake: No match

>
> Try this instead:
>
> $ rake 'foo:bar[123]'


Yuck.

FWIW, you can also embed arguments in the task name, which makes the
command line cleaner. This is yucky in its own special way.

$ cat rakefile
foo_task_pat = /^foo(\w+)$/

make_foo_dep_name =
proc do |taskname|
"foo/#{taskname[foo_task_pat, 1]}"
end

rule foo_task_pat => make_foo_dep_name do |t|
puts "handling rule for #{t.name.inspect}"
end

directory "foo"

file "foo/bar" => "foo" do
system "touch foo/bar"
end
$ rm -rf foo
$ rake foobar
(in /home/vjoel/ruby/misc/rake/args)
handling rule for "foobar"
$ ls foo
bar

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

  Réponse avec citation
Vieux 25/02/2008, 21h23   #5
Jos Backus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

On Tue, Feb 26, 2008 at 06:07:38AM +0900, Joel VanderWerf wrote:
> Jos Backus wrote:
>> $ rake 'foo:bar[123]'

>
> Yuck.


Hey, using []'s in rake wasn't my idea...

--
Jos Backus
jos at catnook.com

  Réponse avec citation
Vieux 25/02/2008, 21h40   #6
Phlip
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

Jos Backus wrote:

> Hey, using []'s in rake wasn't my idea...


Bash:

$ echo ()
>


The () parens are bashoidal delimiters. Other shells probably obey some standard
there, too. I don't know what they do, but I always escape them with \(\), and
my experiment invoked the dreaded subsidiary command prompt, >.

$ echo []

That doesnt' have this problem!

--
Phlip
  Réponse avec citation
Vieux 25/02/2008, 21h44   #7
Rob Biedenharn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

On Feb 25, 2008, at 3:44 PM, Reacher wrote:

> I figured it out
>
> $ rake foo:bar\[123\]
> (in /path/to/my/dir)
> num = 123
>
> BTW, csh is evil



Of course csh is evil! That's nothing new.
http://ooblick.com/text/CshProgrammi...edHarmful.html

This works just fine with bash:

rab://tmp $ cat Rakefile
namespace :foo do
desc 'lol'
task :bar, :num do |t, args|
puts "num = #{args.num}"
end
end
rab://tmp $ rake foo:bar[123]
(in /private/tmp)
num = 123

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com


  Réponse avec citation
Vieux 25/02/2008, 22h01   #8
Reacher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: rake task with arguments

On Feb 25, 3:44pm, Rob Biedenharn <R...@AgileConsultingLLC.com>
wrote:
> On Feb 25, 2008, at 3:44 PM, Reacher wrote:
>
> > I figured it out

>
> > $ rake foo:bar\[123\]
> > (in /path/to/my/dir)
> > num = 123

>
> > BTW, csh is evil

>
> Of course csh is evil! That's nothing new.http://ooblick.com/text/CshProgrammi...edHarmful.html
>
> This works just fine with bash:
>
> rab://tmp $ cat Rakefile
> namespace :foo do
> desc 'lol'
> task :bar, :num do |t, args|
> puts "num = #{args.num}"
> end
> end
> rab://tmp $ rake foo:bar[123]
> (in /private/tmp)
> num = 123
>
> -Rob
>
> Rob Biedenharn http://agileconsultingllc.com
> R...@AgileConsultingLLC.com


When I got my first real job programming, I had no experience with
*NIX .. at all. The shell we worked in was tcsh. Currently, everyone
in our office uses ksh, but I've been slow to conform, since I'm used
to tcsh and it's few but handy niceties. I think the results of this
thread may be the poke needed to move to bash.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h16.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15293 seconds with 16 queries