lib/jazzy/config.rb in jazzy-0.5.0 vs lib/jazzy/config.rb in jazzy-0.6.0

- old
+ new

@@ -9,19 +9,21 @@ module Jazzy # rubocop:disable Metrics/ClassLength class Config # rubocop:disable Style/AccessorMethodName class Attribute - attr_reader :name, :description, :command_line, :default, :parse + attr_reader :name, :description, :command_line, :config_file_key, + :default, :parse def initialize(name, description: nil, command_line: nil, default: nil, parse: ->(x) { x }) - @name = name + @name = name.to_s @description = Array(description) @command_line = Array(command_line) @default = default @parse = parse + @config_file_key = full_command_line_name || @name end def get(config) config.method(name).call end @@ -51,10 +53,25 @@ return if command_line.empty? opt.on(*command_line, *description) do |val| set(config, val) end end + + private + + def full_command_line_name + long_option_names = command_line.map do |opt| + Regexp.last_match(1) if opt =~ %r{ + ^-- # starts with double dash + (?:\[no-\])? # optional prefix for booleans + ([^\s]+) # long option name + }x + end + if long_option_name = long_option_names.compact.first + long_option_name.tr('-', '_') + end + end end # rubocop:enable Style/AccessorMethodName def self.config_attr(name, **opts) attr_accessor name @@ -140,11 +157,11 @@ Array(files).map { |f| expand_path(f) } end config_attr :swift_version, command_line: '--swift-version VERSION', - default: '2.1.1', + default: '2.2', parse: ->(v) do raise 'jazzy only supports Swift 2.0 or later.' if v.to_f < 2 v end @@ -219,10 +236,15 @@ description: 'GitHub URL file prefix of this project (e.g. '\ 'https://github.com/realm/realm-cocoa/tree/v0.87.1)' # ──────── Doc generation options ──────── + config_attr :skip_documentation, + command_line: '--skip-documentation', + description: 'Will skip the documentation generation phase.', + default: false + config_attr :min_acl, command_line: '--min-acl [private | internal | public]', description: 'minimum access control level to document', default: 'public', parse: ->(acl) do @@ -235,11 +257,11 @@ 'comments.', default: false config_attr :hide_documentation_coverage, command_line: '--[no-]hide-documentation-coverage', - description: "Hide \"(X\% documented)\" from the generated documents", + description: 'Hide "(X% documented)" from the generated documents', default: false config_attr :custom_categories, description: ['Custom navigation categories to replace the standard '\ '“Classes, Protocols, etc.”', 'Types not explicitly named '\ @@ -344,15 +366,28 @@ self.base_path = config_path.parent puts "Using config file #{config_path}" config_file = read_config_file(config_path) - self.class.all_config_attrs.each do |attr| - key = attr.name.to_s - if config_file.key?(key) - attr.set_if_unconfigured(self, config_file[key]) + + attrs_by_conf_key, attrs_by_name = %i(config_file_key name).map do |prop| + self.class.all_config_attrs.group_by(&prop) + end + + config_file.each do |key, value| + unless attr = attrs_by_conf_key[key] + message = "WARNING: Unknown config file attribute #{key.inspect}" + if matching_name = attrs_by_name[key] + message << ' (Did you mean ' + message << matching_name.first.config_file_key.inspect + message << '?)' + end + warn message + next end + + attr.first.set_if_unconfigured(self, value) end self.base_path = nil end @@ -402,10 +437,10 @@ if match found = true puts puts attr.name.to_s.tr('_', ' ').upcase puts - puts " Config file: #{attr.name}" + puts " Config file: #{attr.config_file_key}" cmd_line_forms = attr.command_line.select { |opt| opt.is_a?(String) } if cmd_line_forms.any? puts " Command line: #{cmd_line_forms.join(', ')}" end puts