From 59f1a89f4fa6107ba2ae525ce67341391a3790c7 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 27 Feb 2022 12:41:47 -0500 Subject: [PATCH] Add -A CLI flag to show all tasks --- lib/rscons/application.rb | 10 ++++++---- lib/rscons/cli.rb | 8 +++++++- spec/build_tests_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index b8cdf0d..fa680ef 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -54,12 +54,14 @@ module Rscons # List of task(s) to execute. # @param show_tasks [Boolean] # 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] # User-specified variants list. # # @return [Integer] # 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"] = [] @enabled_variants = enabled_variants if enabled_variants == "" && !tasks_and_params.include?("configure") @@ -71,7 +73,7 @@ module Rscons @script.load(rsconscript) enable_variants if show_tasks - show_script_tasks + show_script_tasks(all_tasks) return 0 end apply_task_params(tasks_and_params) @@ -340,10 +342,10 @@ module Rscons end end - def show_script_tasks + def show_script_tasks(all_tasks) puts "Tasks:" Task[].sort.each do |task_name, task| - if task.description + if task.description || all_tasks puts %[ #{sprintf("%-27s", task_name)} #{task.description}] task.params.each do |param_name, param| arg_text = "--#{param_name}" diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index 9f60792..87369b2 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -54,10 +54,15 @@ module Rscons def run_toplevel(argv) rsconscript = nil show_tasks = false + all_tasks = false enabled_variants = "" OptionParser.new do |opts| + opts.on("-A", "--all") do + all_tasks = true + end + opts.on("-b", "--build DIR") do |build_dir| Rscons.application.build_dir = build_dir end @@ -132,7 +137,7 @@ module Rscons end 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 Ansi.write($stderr, :red, e.message, :reset, "\n") 1 @@ -144,6 +149,7 @@ module Rscons Usage: #{$0} [global options] [[task] [task options] ...] Global options: + -A, --all Show all tasks (even without descriptions) in task list -b BUILD, --build=BUILD Set build directory (default: build) -e VS, --variants=VS Enable or disable variants -f FILE Use FILE as Rsconscript diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 8c7b3ee..1fe11a6 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -2956,6 +2956,26 @@ EOF expect(result.stdout).to_not match /^\s*one\b/ expect(result.stdout).to_not match /^\s*two\b/ 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 context "download script method" do