0

As per "How to pass command line arguments to a rake task" I thought the following would work.

$ rake command -- other options

However the invocation fails with an invalid option error. The answer states:

note the --, that's necessary for bypassing standard rake arguments.

It doesn't work for me. Is there a fix?

Community
  • 1
  • 1
AJcodez
  • 31,780
  • 20
  • 84
  • 118

1 Answers1

0

It turns out using key=value syntax works. So to set options use this.

$ rake command option= key=value

Which gives you arguments in the command.

args = ARGV.grep(/=/).map{ |s| [ *s.split(/=/), true ][0, 2] }.to_h
# => { "option" => true, "key" => "value" }

Or simpler for just keys.

args = ARGV.flat_map{ |s| s[/(\w+)=/, 1] }.compact
# => [ "option", "key" ]
AJcodez
  • 31,780
  • 20
  • 84
  • 118