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
- #flag? ⇒ Boolean 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 @options = 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 @options 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.
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 |
#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.
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.
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.
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.
75 76 77 |
# File 'lib/dry/cli/option.rb', line 75 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.
81 82 83 |
# File 'lib/dry/cli/option.rb', line 81 def description_name [: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.
63 64 65 |
# File 'lib/dry/cli/option.rb', line 63 def flag? type == :flag 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.
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 dasherized_name = Inflector.dasherize(name) = [] if boolean? << "--[no-]#{dasherized_name}" elsif flag? << "--#{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 |