ruby / ruby/rake

`$RAKE_PRELOAD` to load custom Ruby file before starting application

Offen
#595 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Ruby
Sterne
2.5k
Forks
650
Ø Merge
6 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne am Einstiegspunkt des rake-Befehls und verfolge, wie Rake.application.run die Rakefile lädt und handle_options aufruft. Ermittle, wie eine Preload-Datei vor run geladen werden könnte, wobei das vorgeschlagene RAKE_PRELOAD-Verhalten erhalten bleibt; abgeschlossen ist die Aufgabe, wenn der Mechanismus vereinbart, implementiert und durch Tests für die Anpassung von Rake.application abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
ruby
Bereich
build-system, cli, tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.