lib/lucid/options.rb in lucid-0.0.3 vs lib/lucid/options.rb in lucid-0.0.4

- old
+ new

@@ -3,10 +3,18 @@ require 'yaml' module Lucid class Options def self.parse(args) + orig_args = args.dup + name = nil + + if orig_args.index("--name") + name_loc = orig_args.index("--name") + 1 + name = orig_args[name_loc] + end + default_options = self.get_options(:default) project_options = self.get_options(:project) combine_options = default_options.merge(project_options) option_parser = OptionParser.new do |opts| @@ -18,11 +26,15 @@ opts.on('-p', '--print', "Echo the Lucid command instead of executing it.") do combine_options[:print] = true end opts.on('-o', '--options OPTIONS', "Options to pass to the tool.") do |options| - combine_options[:options] = options + if options =~ (/^--name/) + combine_options[:c_options] = "#{options} \"#{name}\"" + else + combine_options[:c_options] = options + end end opts.on('-t', '--tags TAGS', "Tags to include or exclude.") do |tags| combine_options[:tags] = tags end @@ -40,12 +52,16 @@ option_parser.parse!(args) # This statement is necessary to get the spec execution pattern from # the command line. This will not be a switch and so it will be the - # only actual command line argument. - combine_options[:pattern] = args.first if args.any? + # only actual command line argument. However, account must be taken + # of the potential of using the --name option, which means that the + # argument to that option will be the first argument and thus the + # second argument will be the spec execution pattern. + combine_options[:pattern] = args.first if args.count == 1 + combine_options[:pattern] = args[1] if args.count == 2 return self.establish(combine_options) end private @@ -67,16 +83,16 @@ end project_options else { - :command => 'cucumber', # :cuke_command - :options => nil, # :cucumber - :spec_path => 'features', # :feature_path + :command => 'cucumber', + :options => nil, + :spec_path => 'features', :step_path => 'features/step_definitions', :requires => [], - :shared => 'true', # value was 'shared' + :shared => 'true', :print => false, :tags => nil, :spec_path_regex => nil, :step_path_regex => nil, :pattern => nil @@ -84,12 +100,16 @@ end end def self.establish(options) + # The next statement makes sure that any project options and command + # line options are merged. + options[:options] += " #{options[:c_options]}" + defaults = self.get_options(:default) - current_set = options.dup # tmp_options + current_set = options.dup current_set[:spec_path] = current_set[:spec_path].gsub(/\\/, '/') current_set[:spec_path] = current_set[:spec_path].sub(/\/$/, '') current_set[:step_path] = current_set[:step_path].gsub(/\\/, '/')