class GLI::CommandLineToken
Abstract base class for a logical element of a command line, mostly so that subclasses can have similar initialization and interface
Public Instance Methods
<=>(other)
click to toggle source
Sort based on primary name
# File lib/gli/command_line_token.rb, line 17 def <=>(other) self.name.to_s <=> other.name.to_s end
names_and_aliases()
click to toggle source
Array of the name and aliases, as string
# File lib/gli/command_line_token.rb, line 22 def names_and_aliases [self.name,self.aliases].flatten.compact.map(&:to_s) end
Private Instance Methods
all_forms(joiner=', ')
click to toggle source
Returns a string of all possible forms of this flag. Mostly intended for printing to the user.
# File lib/gli/command_line_token.rb, line 30 def all_forms(joiner=', ') forms = all_forms_a forms.join(joiner) end
all_forms_a()
click to toggle source
# File lib/gli/command_line_token.rb, line 55 def all_forms_a forms = [self.class.name_as_string(name,negatable?)] if aliases forms |= aliases.map { |one_alias| self.class.name_as_string(one_alias,negatable?) }.sort { |one,two| one.length <=> two.length } end forms end
negatable?()
click to toggle source
# File lib/gli/command_line_token.rb, line 51 def negatable? false; end
parse_names(names)
click to toggle source
Handles dealing with the “names” param, parsing it into the primary name and aliases list
# File lib/gli/command_line_token.rb, line 38 def parse_names(names) # Allow strings; convert to symbols names = [names].flatten.map { |name| name.to_sym } names_hash = {} names.each do |name| raise ArgumentError.new("#{name} has spaces; they are not allowed") if name.to_s =~ /\s/ names_hash[self.class.name_as_string(name)] = true end name = names.shift aliases = names.length > 0 ? names : nil [name,aliases,names_hash] end