From 7651e7b92c15bd5b4bc11fd3dd455be0ea571fd0 Mon Sep 17 00:00:00 2001 From: Go Sueyoshi Date: Fri, 10 Jan 2025 00:28:27 +0900 Subject: [PATCH] rake: Support task arguments and `sh` with env hash (#765) * Support rake task arguments within task block * Support env hash to FileUtils#sh in rake --- gems/rake/13.0/_test/test.rb | 18 ++++++++++++++++++ gems/rake/13.0/rake.rbs | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gems/rake/13.0/_test/test.rb b/gems/rake/13.0/_test/test.rb index 4bcfe9f1..8556c7a2 100644 --- a/gems/rake/13.0/_test/test.rb +++ b/gems/rake/13.0/_test/test.rb @@ -10,5 +10,23 @@ def create_task task :test do ruby "test/unittest.rb" end + + task :test_with_1_arg, :name do |t, args| + value = args[:name] + puts "#{args[:name]}=#{value}" + end + + task :test_with_2_args, %i[name1 name2] do |t, args| + args.each do |name, value| + puts "#{name}=#{value}" + end + end + + task :test_with_sh do + sh "ruby test/unittest_without_env.rb" + + env = { "RACK_ENV" => "test" } + sh env, "ruby test/unittest_with_env.rb" + end end end diff --git a/gems/rake/13.0/rake.rbs b/gems/rake/13.0/rake.rbs index 70ae0e90..89e231fb 100644 --- a/gems/rake/13.0/rake.rbs +++ b/gems/rake/13.0/rake.rbs @@ -3,6 +3,16 @@ module Rake include Rake::DSL end + class Task + end + + class TaskArguments + include Enumerable[untyped] + + def []: (untyped index) -> untyped + def each: () ?{ (untyped, untyped) -> void } -> void + end + module DSL private @@ -16,12 +26,13 @@ module Rake def multitask: (*untyped args) ?{ () -> void } -> void def namespace: (?untyped name) ?{ () -> void } -> void def rule: (*untyped args) ?{ () -> void } -> void - def task: (*untyped args) ?{ () -> void } -> void + def task: (*untyped args) ?{ (Rake::Task, Rake::TaskArguments) -> void } -> void end end module FileUtils def sh: (*String cmd, **untyped options) ?{ (bool, Process::Status) -> void } -> void + | (Hash[String, String] env, *String cmd, **untyped options) ?{ (bool, Process::Status) -> void } -> void def ruby: (*String args, **untyped options) ?{ (bool, Process::Status) -> void } -> void def safe_ln: (*untyped args, **untyped options) -> void def split_all: (String path) -> Array[String]