Class: Climate::Option
- Inherits:
-
Object
- Object
- Climate::Option
- Defined in:
- lib/climate/option.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #add_to(parser) ⇒ Object
- #default ⇒ Object
-
#initialize(name, description, options = {}) ⇒ Option
constructor
A new instance of Option.
- #long ⇒ Object
- #optional? ⇒ Boolean
- #parser ⇒ Object
- #required? ⇒ Boolean
- #short ⇒ Object
- #spec ⇒ Object
- #type ⇒ Object
- #usage(options = {}) ⇒ Object
Constructor Details
#initialize(name, description, options = {}) ⇒ Option
Returns a new instance of Option.
8 9 10 11 12 |
# File 'lib/climate/option.rb', line 8 def initialize(name, description, ={}) @name = name @description = description @options = end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/climate/option.rb', line 5 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/climate/option.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/climate/option.rb', line 6 def @options end |
Instance Method Details
#add_to(parser) ⇒ Object
57 58 59 |
# File 'lib/climate/option.rb', line 57 def add_to(parser) parser.opt(@name, @description, @options) end |
#default ⇒ Object
17 |
# File 'lib/climate/option.rb', line 17 def default ; spec[:default] ; end |
#long ⇒ Object
15 |
# File 'lib/climate/option.rb', line 15 def long ; spec[:long] ; end |
#optional? ⇒ Boolean
19 20 21 |
# File 'lib/climate/option.rb', line 19 def optional? spec.has_key?(:default) end |
#parser ⇒ Object
25 26 27 |
# File 'lib/climate/option.rb', line 25 def parser @parser ||= Trollop::Parser.new.tap {|p| add_to(p) } end |
#required? ⇒ Boolean
23 |
# File 'lib/climate/option.rb', line 23 def required? ; ! optional? ; end |
#short ⇒ Object
16 |
# File 'lib/climate/option.rb', line 16 def short ; spec[:short] ; end |
#spec ⇒ Object
29 30 31 |
# File 'lib/climate/option.rb', line 29 def spec @specs ||= parser.specs[@name] end |
#type ⇒ Object
14 |
# File 'lib/climate/option.rb', line 14 def type ; spec[:type] ; end |
#usage(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/climate/option.rb', line 33 def usage(={}) help = if type == :flag "-#{short}" else "-#{short}<#{type}>" end if [:with_long] help = help + .fetch(:separator, '|') + if type == :flag "--#{long}" else "--#{long}=<#{type}>" end end if optional? && !.fetch(:hide_optional, false) "[#{help}]" else help end end |