Sha256: 6405acf580de42257700cc4c71b4ff70e71031231b190dd83b844783c42324f6
Contents?: true
Size: 1.19 KB
Versions: 25
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true require 'eac_ruby_utils/core_ext' module EacCli class Definition class PositionalArgument DEFAULT_REQUIRED = true enable_listable lists.add_symbol :option, :optional, :repeat, :required, :subcommand common_constructor :name, :options, default: [{}] do options.assert_valid_keys(self.class.lists.option.values) end def build_value(new_value, previous_value) if previous_value.is_a?(::Array) previous_value + [new_value] else new_value end end def default_value repeat? ? [] : nil end def identifier name.to_s.variableize.to_sym end def optional? !required? end def repeat? options[OPTION_REPEAT] end def required? return true if options.key?(OPTION_REQUIRED) && options.fetch(OPTION_REQUIRED) return false if options.key?(OPTION_OPTIONAL) && options.fetch(OPTION_OPTIONAL) DEFAULT_REQUIRED end def subcommand? options[OPTION_SUBCOMMAND] end def to_s "#{self.class.name.demodulize}[#{identifier}]" end end end end
Version data entries
25 entries across 25 versions & 3 rubygems