Given the dummy rake task below
require "optparse" namespace :a do namespace :b do task c: :environment do options = {} OptionParser.new do |parser| parser.banner = "" parser.on("-v", "--verbose", "Run verbosely") do |v| options[:verbose] = v end end.parse! puts "options: #{options}" end end end How should I call it?
From my understanding, the way should be bin/rails a:b:c -v 3 or bin/rails a:b:c -- -v 3
But both ways generate:
Unrecognized command "3" (Rails::Command::UnrecognizedCommandError)
What am I missing here?
I'm running the task on a Mac.
UPDATE 1
a@mac appa % bundle exec rake a:b:c -- -v 3 options: {} rake aborted! Don't know how to build task '3' (See the list of available tasks with `rake --tasks`) /Users/sa/.rbenv/versions/3.3.7/bin/bundle:25:in `load' /Users/sa/.rbenv/versions/3.3.7/bin/bundle:25:in `<main>' (See full trace by running task with --trace)
OptionParserin Rake tasks within Rails, maybebin/railsis already interpreting the options? It might be easier to create a Thor task though which provides these kind of option passing out of the box.