Class: Sprinkles::Opts::GetOpt::Option
- Inherits:
-
T::Struct
- Object
- T::Struct
- Sprinkles::Opts::GetOpt::Option
- Extended by:
- T::Sig
- Defined in:
- lib/sprinkles/opts.rb
Instance Method Summary collapse
- #get_placeholder(default = 'VALUE') ⇒ Object
- #optional? ⇒ Boolean
- #optparse_args ⇒ Object
- #positional? ⇒ Boolean
- #repeated? ⇒ Boolean
Instance Method Details
#get_placeholder(default = 'VALUE') ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sprinkles/opts.rb', line 50 def get_placeholder(default='VALUE') if type.is_a?(Class) && type < T::Enum # if the type is an enum, we can enumerate the possible # values in a rich way possible_values = type.values.map(&:serialize).join("|") return "<#{possible_values}>" end placeholder || default end |
#optional? ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/sprinkles/opts.rb', line 32 def optional? return true unless factory.nil? return true if type.is_a?(T::Types::Union) && type.types.any? { |t| t == T::Utils.coerce(NilClass) } false end |
#optparse_args ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sprinkles/opts.rb', line 62 def optparse_args args = [] if type == T::Boolean args << "-#{short}" if short args << "--[no-]#{long}" if long else args << "-#{short}#{get_placeholder}" if short args << "--#{long}=#{get_placeholder}" if long end args << description if description args end |
#positional? ⇒ Boolean
40 41 42 |
# File 'lib/sprinkles/opts.rb', line 40 def positional? short.nil? && long.nil? end |
#repeated? ⇒ Boolean
45 46 47 |
# File 'lib/sprinkles/opts.rb', line 45 def repeated? type.is_a?(T::Types::TypedArray) || type.is_a?(T::Types::TypedSet) end |