Sha256: 202811b7109aeef55fc819c08f1f669f16b7f9f00296d024857837a6c34b0bb6

Contents?: true

Size: 737 Bytes

Versions: 24

Compression:

Stored size: 737 Bytes

Contents

# frozen_string_literal: true

require "optparse"

module Anyway # :nodoc:
  # Initializes the OptionParser instance using the given configuration
  class OptionParserBuilder
    class << self
      def call(options)
        OptionParser.new do |opts|
          options.each do |key, descriptor|
            opts.on(*option_parser_on_args(key, **descriptor)) do |val|
              yield [key, val]
            end
          end
        end
      end

      private

      def option_parser_on_args(key, flag: false, desc: nil, type: ::String)
        on_args = ["--#{key.to_s.tr("_", "-")}#{flag ? "" : " VALUE"}"]
        on_args << type unless flag
        on_args << desc unless desc.nil?
        on_args
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
anyway_config-2.6.4 lib/anyway/option_parser_builder.rb
anyway_config-2.6.3 lib/anyway/option_parser_builder.rb
anyway_config-2.6.2 lib/anyway/option_parser_builder.rb
anyway_config-2.6.1 lib/anyway/option_parser_builder.rb
anyway_config-2.6.0 lib/anyway/option_parser_builder.rb
runger_config-3.0.1 lib/anyway/option_parser_builder.rb
runger_config-3.0.0 lib/anyway/option_parser_builder.rb
runger_config-2.7.0 lib/anyway/option_parser_builder.rb
runger_config-2.6.1 lib/anyway/option_parser_builder.rb
runger_config-2.6.0 lib/anyway/option_parser_builder.rb
anyway_config-2.5.4 lib/anyway/option_parser_builder.rb
anyway_config-2.5.3 lib/anyway/option_parser_builder.rb
anyway_config-2.5.2 lib/anyway/option_parser_builder.rb
anyway_config-2.5.1 lib/anyway/option_parser_builder.rb
anyway_config-2.5.0 lib/anyway/option_parser_builder.rb
anyway_config-2.4.2 lib/anyway/option_parser_builder.rb
anyway_config-2.4.1 lib/anyway/option_parser_builder.rb
anyway_config-2.4.0 lib/anyway/option_parser_builder.rb
anyway_config-2.3.1 lib/anyway/option_parser_builder.rb
anyway_config-2.3.0 lib/anyway/option_parser_builder.rb