Sha256: 4c84d374d74d7af7b3da68bbb1656b57c974b4d5567cb8b370125d84014c6f38
Contents?: true
Size: 797 Bytes
Versions: 9
Compression:
Stored size: 797 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| opts.accept(AutoCast) { |_1| AutoCast.call(_1) } 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: AutoCast) 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
9 entries across 9 versions & 1 rubygems