Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/rake/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ def truncate(string, width) # :nodoc:

# Display the tasks and prerequisites
def display_prerequisites # :nodoc:
tasks.each do |t|
displayable_tasks = tasks.select { |t|
t.name =~ options.show_prereq_pattern
}

displayable_tasks.each do |t|
puts "#{name} #{t.name}"
t.prerequisites.each { |pre| puts " #{pre}" }
end
Expand Down Expand Up @@ -531,9 +535,11 @@ def standard_rake_options # :nodoc:
"-N", "Do not search parent directories for the Rakefile.",
lambda { |value| options.nosearch = true }
],
["--prereqs", "-P",
"Display the tasks and dependencies, then exit.",
lambda { |value| options.show_prereqs = true }
["--prereqs", "-P [PATTERN]",
"Display the tasks (matching optional PATTERN) and dependencies, then exit.",
lambda { |value|
select_prereqs_to_show(options, value)
}
],
["--quiet", "-q",
"Do not log messages to standard output.",
Expand Down Expand Up @@ -642,6 +648,12 @@ def standard_rake_options # :nodoc:
])
end

def select_prereqs_to_show(options, value) # :nodoc:
options.show_prereqs = true
options.show_prereq_pattern = Regexp.new(value || "")
end
private :select_prereqs_to_show

def select_tasks_to_show(options, show_tasks, value) # :nodoc:
options.show_tasks = show_tasks
options.show_task_pattern = Regexp.new(value || "")
Expand Down
1 change: 1 addition & 0 deletions lib/rake/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Options
attr_accessor :nosearch
attr_accessor :rakelib
attr_accessor :show_all_tasks
attr_accessor :show_prereq_pattern
attr_accessor :show_prereqs
attr_accessor :show_task_pattern
attr_accessor :show_tasks
Expand Down
22 changes: 22 additions & 0 deletions test/test_rake_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,28 @@ def test_display_prereqs
assert_match(/rake default\n( *(a|b)\n){2}/m, out)
end

def test_display_prereqs_with_pattern
@app.last_description = "COMMENT"
t = @app.define_task(Rake::Task, "ci")
t.enhance([:test, :rubocop])
@app.define_task(Rake::Task, "rubocop")
@app.define_task(Rake::Task, "test")
@app.define_task(Rake::Task, "test:system")
@app.in_namespace("ci") do
@app.in_namespace("artifacts") do
@app.define_task(Rake::Task, "export")
end
end
out, = capture_output { @app.run %w[-f -s -P ci --rakelib=""] }
assert @app.options.show_prereqs
assert_equal <<~OUTPUT, out
rake ci
test
rubocop
rake ci:artifacts:export
OUTPUT
end

def test_bad_run
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_output {
Expand Down