Sha256: bf2d311c5a72b873a7d138ec286a5fb6ed73e1592f0087be1f193522565fcd1f
Contents?: true
Size: 1.34 KB
Versions: 205
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true require 'eac_ruby_utils/core_ext' module EacCli class Definition class PositionalArgument DEFAULT_REQUIRED = true DEFAULT_VISIBLE = true enable_listable lists.add_symbol :option, :optional, :repeat, :required, :subcommand, :visible 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 def visible? options.key?(OPTION_VISIBLE) ? options.fetch(OPTION_VISIBLE) : DEFAULT_VISIBLE end end end end
Version data entries
205 entries across 205 versions & 4 rubygems