Class: Dry::CLI::Option Private
- Inherits:
-
Object
- Object
- Dry::CLI::Option
- 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
Direct Known Subclasses
Instance Attribute Summary collapse
- #name ⇒ Object readonly private
- #options ⇒ Object readonly private
Instance Method Summary collapse
- #alias_names ⇒ Object private
- #aliases ⇒ Object private
- #argument? ⇒ Boolean private
- #array? ⇒ Boolean private
- #boolean? ⇒ Boolean private
- #default ⇒ Object private
- #desc ⇒ Object private
- #description_name ⇒ Object private
-
#initialize(name, options = {}) ⇒ Option
constructor
private
A new instance of Option.
- #parser_options ⇒ Object private
- #required? ⇒ Boolean private
- #type ⇒ Object private
- #values ⇒ Object private
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.
20 21 22 23 |
# File 'lib/dry/cli/option.rb', line 20 def initialize(name, = {}) @name = name = end |
Instance Attribute Details
#name ⇒ Object (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.
12 13 14 |
# File 'lib/dry/cli/option.rb', line 12 def name @name end |
#options ⇒ Object (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.
16 17 18 |
# File 'lib/dry/cli/option.rb', line 16 def end |
Instance Method Details
#alias_names ⇒ Object
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.
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 |
#aliases ⇒ Object
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.
27 28 29 |
# File 'lib/dry/cli/option.rb', line 27 def aliases [: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.
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.
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.
58 59 60 |
# File 'lib/dry/cli/option.rb', line 58 def boolean? type == :boolean end |
#default ⇒ Object
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.
70 71 72 |
# File 'lib/dry/cli/option.rb', line 70 def default [:default] end |
#desc ⇒ Object
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.
33 34 35 36 |
# File 'lib/dry/cli/option.rb', line 33 def desc desc = [:desc] values ? "#{desc}: (#{values.join("/")})" : desc end |
#description_name ⇒ Object
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.
76 77 78 |
# File 'lib/dry/cli/option.rb', line 76 def description_name [:label] || name.upcase end |
#parser_options ⇒ Object
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.
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 dasherized_name = Inflector.dasherize(name) = [] if boolean? << "--[no-]#{dasherized_name}" else << "--#{dasherized_name}=#{name}" << "--#{dasherized_name} #{name}" end << Array if array? << values if values .unshift(*alias_names) if aliases.any? << desc if desc 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.
40 41 42 |
# File 'lib/dry/cli/option.rb', line 40 def required? [:required] end |
#type ⇒ Object
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.
46 47 48 |
# File 'lib/dry/cli/option.rb', line 46 def type [:type] end |
#values ⇒ Object
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.
52 53 54 |
# File 'lib/dry/cli/option.rb', line 52 def values [:values] end |