Sha256: e7181129b87bf9534b2bde5d097680d378c41cc5378963a0226438e1def41267
Contents?: true
Size: 1.29 KB
Versions: 3
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true module Cri # The definition of an option. class OptionDefinition attr_reader :short attr_reader :long attr_reader :desc attr_reader :argument attr_reader :multiple attr_reader :block attr_reader :hidden attr_reader :default attr_reader :transform def initialize(short:, long:, desc:, argument:, multiple:, block:, hidden:, default:, transform:) @short = short @long = long @desc = desc @argument = argument @multiple = multiple @block = block @hidden = hidden @default = default @transform = transform if @short.nil? && @long.nil? raise ArgumentError, 'short and long options cannot both be nil' end if @default && @argument == :forbidden raise ArgumentError, 'a default value cannot be specified for flag options' end @default = false if @argument == :forbidden end def to_h { short: @short, long: @long, desc: @desc, argument: @argument, multiple: @multiple, block: @block, hidden: @hidden, default: @default, transform: @transform, } end def formatted_name @long ? '--' + @long : '-' + @short end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cri-2.15.12 | lib/cri/option_definition.rb |
cri-2.15.11 | lib/cri/option_definition.rb |
cri-2.15.10 | lib/cri/option_definition.rb |