Class: CLI::Kit::Args::Definition::Flag

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
OptBase
Defined in:
lib/cli/kit/args/definition.rb

Direct Known Subclasses

Option

Instance Attribute Summary collapse

Attributes included from OptBase

#desc, #name

Instance Method Summary collapse

Methods included from T::Sig

sig

Constructor Details

#initialize(name:, short: nil, long: nil, desc: nil) ⇒ Flag

Returns a new instance of Flag.



149
150
151
152
153
154
155
156
157
158
# File 'lib/cli/kit/args/definition.rb', line 149

def initialize(name:, short: nil, long: nil, desc: nil)
  if long&.start_with?('-') || short&.start_with?('-')
    raise(ArgumentError, 'invalid - prefix')
  end

  @name = name
  @short = short
  @long = long
  @desc = desc
end

Instance Attribute Details

#longObject (readonly)

Returns the value of attribute long.



141
142
143
# File 'lib/cli/kit/args/definition.rb', line 141

def long
  @long
end

#shortObject (readonly)

Returns the value of attribute short.



138
139
140
# File 'lib/cli/kit/args/definition.rb', line 138

def short
  @short
end

Instance Method Details

#as_written_by_userObject



144
145
146
# File 'lib/cli/kit/args/definition.rb', line 144

def as_written_by_user
  long ? "--#{long}" : "-#{short}"
end