Sha256: 2a49e69ec61f7a261321300e948f61373f12ed147f62494735116527b219e346
Contents?: true
Size: 1.08 KB
Versions: 10
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require "optparse" require "forwardable" module Pragmater module CLI module Options # Coalesces all options and arguments into a single hash for further processing. class Assembler extend Forwardable PARSER = OptionParser.new nil, 40, " " SECTIONS = [Core, InsertRemove, Configuration].freeze EXCEPTIONS = [ OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::InvalidArgument ].freeze delegate %i[to_s] => :parser def initialize sections: SECTIONS, parser: PARSER, exceptions: EXCEPTIONS @sections = sections @parser = parser @options = {} @exceptions = exceptions end def call arguments = [] sections.each { |section| section.new(options, parser: parser).call } parser.parse! arguments options rescue *EXCEPTIONS {} end private attr_reader :parser, :sections, :options, :exceptions end end end end
Version data entries
10 entries across 10 versions & 1 rubygems