class Argy::Option

An option to be parsed from the command line

Attributes

aliases[R]

A list of alternative flags @return [Array<String>]

Public Class Methods

new(*args, aliases: [], **opts) click to toggle source

Create a new Option @param name [Symbol] name of the parameter @param aliases [Array<String>] a list of alternative flags @param desc [String,nil] description for the parameter @param type [Symbol,#call] type of parameter @param default [Object] default value for the parameter @param required [TrueClass,FalseClass] whether or not the field is required

Calls superclass method
# File lib/argy/option.rb, line 17
def initialize(*args, aliases: [], **opts)
  super(*args, **opts)
  @aliases = aliases
end

Public Instance Methods

label() click to toggle source

The display label for the argument @return [String]

# File lib/argy/option.rb, line 24
def label
  case type
  when :boolean
    "--[no-]#{name.to_s.tr("_", "-")}"
  else
    "--#{name.to_s.tr("_", "-")}"
  end
end
to_option_parser() click to toggle source

@private

# File lib/argy/option.rb, line 34
def to_option_parser
  options = []
  options << aliases.join(" ") unless aliases.empty?

  case type
  when :boolean
    options << label
  else
    options << "#{label}=#{name.to_s.upcase}"
    options << "#{label} #{name.to_s.upcase}"
  end

  options << desc if desc
  options
end