Skip to content

Commit

Permalink
rake: Support task arguments and sh with env hash (#765)
Browse files Browse the repository at this point in the history
* Support rake task arguments within task block

* Support env hash to FileUtils#sh in rake
  • Loading branch information
sue445 authored Jan 9, 2025
1 parent ef53a5b commit 7651e7b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions gems/rake/13.0/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion gems/rake/13.0/rake.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand Down

0 comments on commit 7651e7b

Please sign in to comment.