From 90300a1606f540293dc50c9d523763eb95314e90 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 25 Nov 2018 16:02:04 -0500 Subject: [PATCH] pass operation options via Hash instead of setting Application attributes --- lib/rscons/application.rb | 19 ++++++++----------- lib/rscons/cli.rb | 13 +++++++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 9a1e39d..c46edef 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -15,14 +15,6 @@ module Rscons # Access any variables set on the rscons command-line. attr_reader :vars - # @return [String] - # Build directory (default "build"). - attr_accessor :build_dir - - # @return [String] - # Installation prefix (default "/usr/local"). - attr_accessor :prefix - def initialize @n_threads = determine_n_threads @vars = VarSet.new @@ -36,10 +28,12 @@ module Rscons # The operation to perform (e.g. "clean", "configure", "build", etc...) # @param script [Script] # The script. + # @param operation_options [Hash] + # Option values from the CLI for the operation. # # @return [Integer] # Process exit code (0 on success). - def run(operation, script) + def run(operation, script, operation_options) @script = script case operation when "build" @@ -48,7 +42,7 @@ module Rscons when "clean" clean when "configure" - configure + configure(operation_options) else $stderr.puts "Unknown operation: #{operation}" 1 @@ -79,8 +73,11 @@ module Rscons # Configure the project. # + # @param options [Hash] + # Options. + # # @return [void] - def configure + def configure(options) cache = Cache.instance cache.configuration_data = {} if project_name = @script.project_name diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index f9b05a0..fd42a3e 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -110,9 +110,9 @@ module Rscons exit 0 end - parse_operation_args(operation, argv) + operation_options = parse_operation_args(operation, argv) - exit Rscons.application.run(operation, script) + exit Rscons.application.run(operation, script, operation_options) end private @@ -125,17 +125,22 @@ module Rscons end def parse_configure_args(argv) + options = { + build_dir: "build", + prefix: "/usr/local", + } OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options]" opts.on("-b", "--build DIR") do |build_dir| - Rscons.application.build_dir = build_dir + options[:build_dir] = build_dir end opts.on("--prefix PREFIX") do |prefix| - Rscons.application.prefix = prefix + options[:prefix] = prefix end end.order!(argv) + options end end