C++ の可変引数関数のように、任意の数の引数を処理できる rake タスクを定義する必要があります。しかし、rake の DSL 内でそれを定義する方法が見つかりませんでした。
任意の量の引数を処理できる rake タスクを作成するにはどうすればよいですか? 例が役に立ちます。
ありがとう!
ドキュメントに記載されているように、バージョン 0.8 の Rake はこれを処理できません (追加の引数は単に無視されます)。
ただし、 Thorの使用に切り替えることができれば、この動作を得ることができます。デモを行うために、次のThorfile内容で を作成します。
class VariableArguments < Thor
desc 'multiple [ARGS]', "Task with multiple arguments"
def multiple(*args)
p args
end
end
そして、次のように呼び出します。
$ thor variable_arguments:multiple one two three four five six
これにより、次のように出力されます。
["one", "two", "three", "four", "five", "six"]
(Thor 0.14.6 を使用してテスト済み)
Building on the post here: How do I pass command line arguments to a rake task I would think that the arg1 would simply be an array that you could do a array.each do |arg|. From the command line it would then be a matter of them passing in a quoted, comma-delimited list.