`$RAKE_PRELOAD` to load custom Ruby file before starting application
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- ruby
- Domain
- build-system, cli, tooling
Research direction
Start at the rake command entry point and follow how Rake.application.run loads the Rakefile and invokes handle_options. Determine how a preload file could be loaded before run while preserving the proposed RAKE_PRELOAD behavior; done means the mechanism is agreed, implemented, and covered by tests for customizing Rake.application.
Written by the indexing model from the issue text.
Description
Rake application loads Rakefile AFTER Rake.application.run() started.
Therefore it is not able to customize Rake.application.run() (or other methods defined in Rake.application) in Rakefile.
For example, I want to change Rake::Application#handle_options() to use parser.order(argv) instead of parser.parse(argv) in order not to parse options after task names.
(I'm developing rake extension to allow command-line options for each task, and parser.order() is necessary for this purpose.)
Here is my challenge (Rakefile):
## Rakefile
module Rake
Application.class_eval do
def handle_options(argv)
set_default_options
OptionParser.new do |opts|
opts.banner = "#{Rake.application.name} [-f rakefile] {options} targets..."
opts.separator ""
opts.separator "Options are ..."
opts.on_tail("-h", "--help", "-H", "Display this help message.") do
puts opts
exit
end
standard_rake_options.each { |args| opts.on(*args) }
opts.environment("RAKEOPT")
#end.parse(argv) # !! original !!
end.order(argv) # !! customize !!
end
end
end
But the above Rakefile doesn't work intendedly because Rake application loads Rakefile after Rake.application.run() started.
Therefore, I hope Rake to provide a certain method to load custom ruby file before Rake.application.run() started.
One solution is to load a ruby file specified by the $RAKE_PRELOAD environment variable in rake command.
rake command:
#!/usr/bin/env ruby
require "rake"
preload = ENV['RAKE_PRELOAD'] # !!!
if preload && ! preload.empty? # !!!
require preload # !!!
end # !!!
Rake.application.run
I'd like the dev team to consider this idea.
- Dominant language
- Ruby
- Stars
- 2.5k
- Forks
- 649
- Avg merge
- 4m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/rake
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
rake -P output is ambiguous with prereq namespacesPossibly taken @leoarnold claimed this 110 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 28/100
-
FileList#<< bypasses exclusions while FileList#include respects themPossibly taken @hsbt claimed this 124 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 45/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
cline/mcp-marketplace#3886 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jetrockets/recorder#61 ·
-
PROJECT: website-redesign
Difficulty 1/5 Under an hour Newbie friendliness 72/100
thewca/worldcubeassociation.org#16617 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day