Class: Dry::CLI::Option Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/cli/option.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Command line option

Since:

  • 0.1.0

Direct Known Subclasses

Argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Option.

Since:

  • 0.1.0



20
21
22
23
# File 'lib/dry/cli/option.rb', line 20

def initialize(name, options = {})
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



12
13
14
# File 'lib/dry/cli/option.rb', line 12

def name
  @name
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



16
17
18
# File 'lib/dry/cli/option.rb', line 16

def options
  @options
end

Instance Method Details

#alias_namesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



116
117
118
119
120
121
122
123
# File 'lib/dry/cli/option.rb', line 116

def alias_names
  aliases
    .map { |name| name.gsub(/^-{1,2}/, "") }
    .compact
    .uniq
    .map { |name| name.size == 1 ? "-#{name}" : "--#{name}" }
    .map { |name| boolean? || flag? ? name : "#{name} VALUE" }
end

#aliasesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



27
28
29
# File 'lib/dry/cli/option.rb', line 27

def aliases
  options[:aliases] || []
end

#argument?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0



87
88
89
# File 'lib/dry/cli/option.rb', line 87

def argument?
  false
end

#array?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.3.0



69
70
71
# File 'lib/dry/cli/option.rb', line 69

def array?
  type == :array
end

#boolean?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0



58
59
60
# File 'lib/dry/cli/option.rb', line 58

def boolean?
  type == :boolean
end

#defaultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



75
76
77
# File 'lib/dry/cli/option.rb', line 75

def default
  options[:default]
end

#descObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



33
34
35
36
# File 'lib/dry/cli/option.rb', line 33

def desc
  desc = options[:desc]
  values ? "#{desc}: (#{values.join("/")})" : desc
end

#description_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



81
82
83
# File 'lib/dry/cli/option.rb', line 81

def description_name
  options[:label] || name.upcase
end

#flag?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0



63
64
65
# File 'lib/dry/cli/option.rb', line 63

def flag?
  type == :flag
end

#parser_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dry/cli/option.rb', line 94

def parser_options
  dasherized_name = Inflector.dasherize(name)
  parser_options  = []

  if boolean?
    parser_options << "--[no-]#{dasherized_name}"
  elsif flag?
    parser_options << "--#{dasherized_name}"
  else
    parser_options << "--#{dasherized_name}=#{name}"
    parser_options << "--#{dasherized_name} #{name}"
  end

  parser_options << Array if array?
  parser_options << values if values
  parser_options.unshift(*alias_names) if aliases.any?
  parser_options << desc if desc
  parser_options
end

#required?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0



40
41
42
# File 'lib/dry/cli/option.rb', line 40

def required?
  options[:required]
end

#typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



46
47
48
# File 'lib/dry/cli/option.rb', line 46

def type
  options[:type]
end

#valuesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



52
53
54
# File 'lib/dry/cli/option.rb', line 52

def values
  options[:values]
end