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,17 +55,7 @@ module Rscons
private private
def run_toplevel(argv) def add_global_options(opts)
rsconscript = nil
do_help = false
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.on("-f FILE") do |f|
rsconscript = f
end
opts.on("-j NTHREADS") do |n_threads| opts.on("-j NTHREADS") do |n_threads|
Rscons.application.n_threads = n_threads.to_i Rscons.application.n_threads = n_threads.to_i
end end
@ -82,6 +72,19 @@ module Rscons
opts.on("-v", "--verbose") do opts.on("-v", "--verbose") do
Rscons.application.verbose = true Rscons.application.verbose = true
end end
end
def run_toplevel(argv)
rsconscript = nil
do_help = false
OptionParser.new do |opts|
add_global_options(opts)
opts.on("-f FILE") do |f|
rsconscript = f
end
opts.on("--version") do opts.on("--version") do
puts "Rscons version #{Rscons::VERSION}" puts "Rscons version #{Rscons::VERSION}"
@ -133,17 +136,18 @@ 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
when "configure"
parse_configure_args(opts, argv, options)
end
end.order!(argv)
options
end
def parse_configure_args(opts, argv, options)
opts.on("-b", "--build DIR") do |build_dir| opts.on("-b", "--build DIR") do |build_dir|
options[:build_dir] = build_dir options[:build_dir] = build_dir
end end
@ -151,8 +155,6 @@ module Rscons
opts.on("--prefix PREFIX") do |prefix| opts.on("--prefix PREFIX") do |prefix|
options[:prefix] = prefix options[:prefix] = prefix
end end
end.order!(argv)
options
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