Class: Argy::Option

Inherits:
Parameter show all
Defined in:
lib/argy/option.rb

Overview

An option to be parsed from the command line

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, aliases: [], **opts) ⇒ Option

Create a new Option

Parameters:

  • name (Symbol)

    name of the parameter

  • aliases (Array<String>) (defaults to: [])

    a list of alternative flags

  • desc (String, nil)

    description for the parameter

  • type (Symbol, #call)

    type of parameter

  • default (Object)

    default value for the parameter

  • required (TrueClass, FalseClass)

    whether or not the field is required



17
18
19
20
# File 'lib/argy/option.rb', line 17

def initialize(*args, aliases: [], **opts)
  super(*args, **opts)
  @aliases = aliases
end

Instance Attribute Details

#aliasesArray<String> (readonly)

A list of alternative flags

Returns:

  • (Array<String>)


8
9
10
# File 'lib/argy/option.rb', line 8

def aliases
  @aliases
end

Instance Method Details

#labelString

The display label for the argument

Returns:

  • (String)


24
25
26
27
28
29
30
31
# 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