Last active
April 7, 2023 14:51
-
-
Save garmoshka-mo/f81a03fff8dc6a5d97e7b75d3e8d2042 to your computer and use it in GitHub Desktop.
Fix rake tasks to accept arguments in normal bash way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Insert this into Rakefile before Rails.application.load_tasks: require './lib/rake_patch.rb' | |
Rake::Application.class_eval do | |
alias origin_top_level top_level | |
def top_level | |
@top_level_tasks = [top_level_tasks.join(' ')] | |
origin_top_level | |
end | |
def parse_task_string(_) | |
args = ARGV.clone | |
return args.shift, | |
args.reject{|_| _ =~ /^(\w+)=(.*)$/} # clean ENV variables | |
.presence | |
end | |
end | |
Rake::Task.class_eval do | |
class DummyArguments < Array | |
def new_scope(_) | |
self | |
end | |
end | |
def invoke(*args) | |
wrapped_args = DummyArguments.new | |
wrapped_args.concat args | |
invoke_with_call_chain(wrapped_args, Rake::InvocationChain::EMPTY) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment