Add -A CLI flag to show all tasks

This commit is contained in:
Josh Holtrop 2022-02-27 12:41:47 -05:00
parent ea66501311
commit 59f1a89f4f
3 changed files with 33 additions and 5 deletions

View File

@ -54,12 +54,14 @@ module Rscons
# List of task(s) to execute. # List of task(s) to execute.
# @param show_tasks [Boolean] # @param show_tasks [Boolean]
# Flag to show tasks and exit. # Flag to show tasks and exit.
# @param all_tasks [Boolean]
# Flag to show all tasks (not just those with a description).
# @param enabled_variants [String] # @param enabled_variants [String]
# User-specified variants list. # User-specified variants list.
# #
# @return [Integer] # @return [Integer]
# Process exit code (0 on success). # Process exit code (0 on success).
def run(rsconscript, tasks_and_params, show_tasks, enabled_variants) def run(rsconscript, tasks_and_params, show_tasks, all_tasks, enabled_variants)
Cache.instance["failed_commands"] = [] Cache.instance["failed_commands"] = []
@enabled_variants = enabled_variants @enabled_variants = enabled_variants
if enabled_variants == "" && !tasks_and_params.include?("configure") if enabled_variants == "" && !tasks_and_params.include?("configure")
@ -71,7 +73,7 @@ module Rscons
@script.load(rsconscript) @script.load(rsconscript)
enable_variants enable_variants
if show_tasks if show_tasks
show_script_tasks show_script_tasks(all_tasks)
return 0 return 0
end end
apply_task_params(tasks_and_params) apply_task_params(tasks_and_params)
@ -340,10 +342,10 @@ module Rscons
end end
end end
def show_script_tasks def show_script_tasks(all_tasks)
puts "Tasks:" puts "Tasks:"
Task[].sort.each do |task_name, task| Task[].sort.each do |task_name, task|
if task.description if task.description || all_tasks
puts %[ #{sprintf("%-27s", task_name)} #{task.description}] puts %[ #{sprintf("%-27s", task_name)} #{task.description}]
task.params.each do |param_name, param| task.params.each do |param_name, param|
arg_text = "--#{param_name}" arg_text = "--#{param_name}"

View File

@ -54,10 +54,15 @@ module Rscons
def run_toplevel(argv) def run_toplevel(argv)
rsconscript = nil rsconscript = nil
show_tasks = false show_tasks = false
all_tasks = false
enabled_variants = "" enabled_variants = ""
OptionParser.new do |opts| OptionParser.new do |opts|
opts.on("-A", "--all") do
all_tasks = true
end
opts.on("-b", "--build DIR") do |build_dir| opts.on("-b", "--build DIR") do |build_dir|
Rscons.application.build_dir = build_dir Rscons.application.build_dir = build_dir
end end
@ -132,7 +137,7 @@ module Rscons
end end
begin begin
Rscons.application.run(rsconscript, tasks_and_params, show_tasks, enabled_variants) Rscons.application.run(rsconscript, tasks_and_params, show_tasks, all_tasks, enabled_variants)
rescue RsconsError => e rescue RsconsError => e
Ansi.write($stderr, :red, e.message, :reset, "\n") Ansi.write($stderr, :red, e.message, :reset, "\n")
1 1
@ -144,6 +149,7 @@ module Rscons
Usage: #{$0} [global options] [[task] [task options] ...] Usage: #{$0} [global options] [[task] [task options] ...]
Global options: Global options:
-A, --all Show all tasks (even without descriptions) in task list
-b BUILD, --build=BUILD Set build directory (default: build) -b BUILD, --build=BUILD Set build directory (default: build)
-e VS, --variants=VS Enable or disable variants -e VS, --variants=VS Enable or disable variants
-f FILE Use FILE as Rsconscript -f FILE Use FILE as Rsconscript

View File

@ -2956,6 +2956,26 @@ EOF
expect(result.stdout).to_not match /^\s*one\b/ expect(result.stdout).to_not match /^\s*one\b/
expect(result.stdout).to_not match /^\s*two\b/ expect(result.stdout).to_not match /^\s*two\b/
end end
context "with -A flag" do
it "displays all tasks and their parameters" do
test_dir "tasks"
result = run_rscons(args: %w[-f tasks.rb -AT])
expect(result.stderr).to eq ""
expect(result.status).to eq 0
verify_lines(lines(result.stdout), [
"Tasks:",
/\bone\b/,
/\btwo\b/,
/\bthree\b\s+Task three/,
/\bfour\b\s+Task four/,
/--myparam=MYPARAM\s+My special parameter/,
/--myp2\s+My parameter 2/,
/\bfive\b/,
/\bsix\b/,
])
end
end
end end
context "download script method" do context "download script method" do