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



109
110
111
112
113
114
115
116
# File 'lib/dry/cli/option.rb', line 109

def alias_names
  aliases
    .map { |name| name.gsub(/^-{1,2}/, "") }
    .compact
    .uniq
    .map { |name| name.size == 1 ? "-#{name}" : "--#{name}" }
    .map { |name| boolean? ? 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



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

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



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

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



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

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



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

def description_name
  options[:label] || name.upcase
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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dry/cli/option.rb', line 89

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

  if boolean?
    parser_options << "--[no-]#{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