From 7c82cfaebc943695e6b5711f4588d9b223c73350 Mon Sep 17 00:00:00 2001 From: Watson Date: Fri, 28 Sep 2018 22:40:51 +0900 Subject: [PATCH] update Rakefile (use optparse for parsing task arguments) --- README.md | 12 ++++++++--- Rakefile | 60 +++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f7c0e96..5ac28c7 100644 --- a/README.md +++ b/README.md @@ -78,10 +78,10 @@ Following will run all tests in `spec/` directory. $ rake test ``` -Alternatively, you can give spec names as the arguments for this task. E.g., following will run only `help_spec.rb` and `version_spec.rb`: +Alternatively, you can give spec names with the `--list` (`-l`) option for this task. E.g., following will run only `help_spec.rb` and `version_spec.rb`: ``` -$ rake "test[help,version]" +$ rake test -- -l help,version ``` ### Showing all available tasks @@ -92,9 +92,15 @@ Following will show all available tasks with a short description. $ rake -T ``` +In addition to that, for options available tasks (e.g., `rake test` and `rake run_texdoc`) you can get options information with `-h` option for each task: + +``` +$ rake test -- -h +``` + ## Further Information -More specific information (e.g. TODO) can be found in the Wiki of our GitHub repository. Please visit: +More specific information (e.g., TODO) can be found in the Wiki of our GitHub repository. Please visit: * diff --git a/Rakefile b/Rakefile index c1e73cc..f0be631 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require 'rake/clean' require 'pathname' +require 'optparse' # basics TEXDOC_VERSION = "3.0" @@ -92,31 +93,68 @@ task :uninstall do safe_unlink [TEXDOC_LINK, TEXDOC_CNF_LINK] end -desc "Run tests (only listed specs, if specified)" -task :test => [PS_TEXDOC_LINK, PS_TEXDOC_CNF_LINK] do |task, args| +desc "Run tests [options available]" +task :test => [PS_TEXDOC_LINK, PS_TEXDOC_CNF_LINK] do + # parse options + options = {} + if ARGV.delete("--") + OptionParser.new do |opts| + opts.banner = "Usage: rake test [-- OPTION...]" + opts.on("-o", "--opts=OPTS", "Pass OPTS to RSpec") do |args| + options[:args] = args + end + opts.on("-l", "--list=LIST", "Load only specified specs in LIST") do |args| + options[:list] = args + end + end.parse!(ARGV) + end + # use controlled environment ENV["TEXMFHOME"] = PS_TEXMF.to_s # check version sh "texlua #{TEXDOC_TLU} -f" - # run rspec - args = args.to_a - if args.size > 0 - f_list = args.map{|f| "spec/#{f}_spec.rb"}.join(" ") - sh "bundle exec rspec #{f_list}" + # construct options + opt_args = if options[:args] + " " + options[:args].strip else - sh "bundle exec rspec" + "" end + opt_files = if options[:list] + " " + options[:list].split(",").map{|i|"spec/#{i.strip}_spec.rb"}.join(" ") + else + "" + end + + # run rspec + sh "bundle exec rspec" + opt_args + opt_files + + # make sure to end this process + exit 0 end -desc "Run Texdoc without installing (for debug purpose)" -task :run_texdoc => [PS_TEXDOC_LINK, PS_TEXDOC_CNF_LINK] do |task, args| +desc "Run Texdoc without installing [options available]" +task :run_texdoc => [PS_TEXDOC_LINK, PS_TEXDOC_CNF_LINK] do + # parse options + options = {} + if ARGV.delete("--") + OptionParser.new do |opts| + opts.banner = "Usage: rake run_texdoc [-- OPTION...]" + opts.on("-a", "--args=ARGS", "Pass ARGS to Texdoc") do |args| + options[:args] = args + end + end.parse!(ARGV) + end + # use controlled environment ENV["TEXMFHOME"] = PS_TEXMF.to_s # run texdoc - sh "texlua #{TEXDOC_TLU} #{args.to_a.join(' ')}" + sh "texlua #{TEXDOC_TLU} #{options[:args]}" + + # make sure to end this process + exit 0 end desc "Generate a pre-hashed cache file"