Class: Laborantin::Command::Option
- Inherits:
-
Object
- Object
- Laborantin::Command::Option
- Includes:
- Metaprog::Completeable
- Defined in:
- lib/laborantin/core/command.rb
Overview
An Option for a Command, to help us building a nice DSL for you.
Instance Attribute Summary collapse
-
#cli_long ⇒ Object
readonly
The long option flag of the command line (e.g. ‘–trust’).
-
#cli_short ⇒ Object
readonly
The short option flag of the command line (e.g. ‘-t’).
-
#default_type ⇒ Object
readonly
The type to expect for a value (give a class among those understood by OptParse).
-
#default_value ⇒ Object
readonly
The default value of this option.
-
#description ⇒ Object
readonly
The description to provide feedback/help.
-
#name ⇒ Object
readonly
The name of the option.
Attributes included from Metaprog::Completeable
Instance Method Summary collapse
-
#default(val) ⇒ Object
Sets the default value of the option.
-
#describe(str) ⇒ Object
Sets the description of the option.
-
#description_with_default ⇒ Object
Returns the description followed by the default value in parenthesis.
-
#initialize(name) ⇒ Option
constructor
A new instance of Option.
-
#long(str) ⇒ Object
Sets the cli_long option flag (e.g. long ‘–trust’).
-
#short(str) ⇒ Object
Sets the cli_short option flag (e.g. short ‘-t’).
-
#type(klass) ⇒ Object
Sets the type to expect for the option.
Methods included from Metaprog::Completeable
#complete, #completion_propositions_iterating_on
Constructor Details
#initialize(name) ⇒ Option
Returns a new instance of Option.
57 58 59 |
# File 'lib/laborantin/core/command.rb', line 57 def initialize(name) @name = name end |
Instance Attribute Details
#cli_long ⇒ Object (readonly)
The long option flag of the command line (e.g. ‘–trust’)
46 47 48 |
# File 'lib/laborantin/core/command.rb', line 46 def cli_long @cli_long end |
#cli_short ⇒ Object (readonly)
The short option flag of the command line (e.g. ‘-t’)
43 44 45 |
# File 'lib/laborantin/core/command.rb', line 43 def cli_short @cli_short end |
#default_type ⇒ Object (readonly)
The type to expect for a value (give a class among those understood by OptParse)
55 56 57 |
# File 'lib/laborantin/core/command.rb', line 55 def default_type @default_type end |
#default_value ⇒ Object (readonly)
The default value of this option.
52 53 54 |
# File 'lib/laborantin/core/command.rb', line 52 def default_value @default_value end |
#description ⇒ Object (readonly)
The description to provide feedback/help.
49 50 51 |
# File 'lib/laborantin/core/command.rb', line 49 def description @description end |
#name ⇒ Object (readonly)
The name of the option.
40 41 42 |
# File 'lib/laborantin/core/command.rb', line 40 def name @name end |
Instance Method Details
#default(val) ⇒ Object
Sets the default value of the option.
77 78 79 |
# File 'lib/laborantin/core/command.rb', line 77 def default(val) @default_value = val end |
#describe(str) ⇒ Object
Sets the description of the option.
72 73 74 |
# File 'lib/laborantin/core/command.rb', line 72 def describe(str) @description = str end |
#description_with_default ⇒ Object
Returns the description followed by the default value in parenthesis.
87 88 89 |
# File 'lib/laborantin/core/command.rb', line 87 def description_with_default "#{description} (default: #{default_value})." end |
#long(str) ⇒ Object
Sets the cli_long option flag (e.g. long ‘–trust’)
67 68 69 |
# File 'lib/laborantin/core/command.rb', line 67 def long(str) @cli_long = str end |
#short(str) ⇒ Object
Sets the cli_short option flag (e.g. short ‘-t’)
62 63 64 |
# File 'lib/laborantin/core/command.rb', line 62 def short(str) @cli_short = str end |
#type(klass) ⇒ Object
Sets the type to expect for the option.
82 83 84 |
# File 'lib/laborantin/core/command.rb', line 82 def type(klass) @default_type = klass end |