class EcoRake class Option module Mirror # It allows to redirect options # @param value [String, Symbol] the value to use. # @return [String] command option with value def mirror(value = :not_used, raise: false) opt = name_hyphened return boolean_mirror(value) unless argument? missing = (value == :not_used) && !default? msg = "required argument value #{argument} for option #{name} (#{short})" raise ArgumentError, msg if missing && argument_required? && raise return nil if missing && argument_required? value = value == :not_used ? default : value "#{opt} \"#{value}\"" end private # Implements the mirror of Boolean options/switches. def boolean_mirror(value = :not_used) opt = name_hyphened puts "boolean_mirror (#{value}): #{opt}" if name == :no_get return nil unless [TrueClass, NilClass, FalseClass].any? {|klass| type_coercion == klass} enabled_value = !boolean_name? || [TrueClass, NilClass].any? {|klass| type_coercion == klass} return opt if value == enabled_value return name_false_hypen if boolean_name? && value == !enabled_value end end end end