make global CLI options available under subcommands - close #86

This commit is contained in:
Josh Holtrop 2019-01-03 13:50:01 -05:00
parent 9f9b7f0bf4
commit 31ef45258f
2 changed files with 42 additions and 33 deletions

View File

@ -55,34 +55,37 @@ module Rscons
private private
def add_global_options(opts)
opts.on("-j NTHREADS") do |n_threads|
Rscons.application.n_threads = n_threads.to_i
end
opts.on("-r", "--color MODE") do |color_mode|
case color_mode
when "off"
Rscons.application.do_ansi_color = false
when "force"
Rscons.application.do_ansi_color = true
end
end
opts.on("-v", "--verbose") do
Rscons.application.verbose = true
end
end
def run_toplevel(argv) def run_toplevel(argv)
rsconscript = nil rsconscript = nil
do_help = false do_help = false
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
add_global_options(opts)
opts.on("-f FILE") do |f| opts.on("-f FILE") do |f|
rsconscript = f rsconscript = f
end end
opts.on("-j NTHREADS") do |n_threads|
Rscons.application.n_threads = n_threads.to_i
end
opts.on("-r", "--color MODE") do |color_mode|
case color_mode
when "off"
Rscons.application.do_ansi_color = false
when "force"
Rscons.application.do_ansi_color = true
end
end
opts.on("-v", "--verbose") do
Rscons.application.verbose = true
end
opts.on("--version") do opts.on("--version") do
puts "Rscons version #{Rscons::VERSION}" puts "Rscons version #{Rscons::VERSION}"
exit 0 exit 0
@ -133,28 +136,27 @@ module Rscons
end end
def parse_operation_args(operation, argv) def parse_operation_args(operation, argv)
case operation
when "configure"
parse_configure_args(argv)
end
end
def parse_configure_args(argv)
options = {} options = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]" add_global_options(opts)
case operation
opts.on("-b", "--build DIR") do |build_dir| when "configure"
options[:build_dir] = build_dir parse_configure_args(opts, argv, options)
end
opts.on("--prefix PREFIX") do |prefix|
options[:prefix] = prefix
end end
end.order!(argv) end.order!(argv)
options options
end end
def parse_configure_args(opts, argv, options)
opts.on("-b", "--build DIR") do |build_dir|
options[:build_dir] = build_dir
end
opts.on("--prefix PREFIX") do |prefix|
options[:prefix] = prefix
end
end
end end
end end
end end

View File

@ -1978,6 +1978,13 @@ EOF
expect(result.stderr).to eq "" expect(result.stderr).to eq ""
expect(result.stdout).to match /gcc.*-o.*simple/ expect(result.stdout).to match /gcc.*-o.*simple/
end end
it "echoes commands by default with -v after build operation" do
test_dir('simple')
result = run_rscons(op: %w[build -v])
expect(result.stderr).to eq ""
expect(result.stdout).to match /gcc.*-o.*simple/
end
end end
end end