Class: Laborantin::Command::Option

Inherits:
Object
  • Object
show all
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

Attributes included from Metaprog::Completeable

#completion_block

Instance Method Summary collapse

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_longObject (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_shortObject (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_typeObject (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_valueObject (readonly)

The default value of this option.



52
53
54
# File 'lib/laborantin/core/command.rb', line 52

def default_value
  @default_value
end

#descriptionObject (readonly)

The description to provide feedback/help.



49
50
51
# File 'lib/laborantin/core/command.rb', line 49

def description
  @description
end

#nameObject (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_defaultObject

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