lib/anyway/optparse_config.rb in anyway_config-2.0.0.pre2 vs lib/anyway/optparse_config.rb in anyway_config-2.0.0.rc1

- old
+ new

@@ -1,15 +1,13 @@ # frozen_string_literal: true require "anyway/option_parser_builder" require "anyway/ext/deep_dup" -require "anyway/ext/string_serialize" module Anyway using Anyway::Ext::DeepDup - using Anyway::Ext::StringSerialize # Adds ability to use script options as the source # of configuration (via optparse) module OptparseConfig module ClassMethods @@ -19,11 +17,15 @@ end end def describe_options(**hargs) hargs.each do |name, desc| - option_parser_descriptors[name.to_s][:desc] = desc + if String === desc + option_parser_descriptors[name.to_s][:desc] = desc + else + option_parser_descriptors[name.to_s].merge!(desc) + end end end def flag_options(*args) args.each do |name| @@ -67,21 +69,23 @@ end end def option_parser @option_parser ||= begin - OptionParserBuilder.call(self.class.option_parser_options) do |key, arg| - set_value(key, arg.is_a?(String) ? arg.serialize : arg) + OptionParserBuilder.call(self.class.option_parser_options) do |key, val| + write_config_attr(key, val) end.tap do |parser| self.class.option_parser_extensions.map do |extension| extension.call(parser, self) end end end end def parse_options!(options) - option_parser.parse!(options) + Tracing.with_trace_source(type: :options) do + option_parser.parse!(options) + end end def self.included(base) base.extend ClassMethods end