Class: Relish::Command::Dsl::HelpText

Inherits:
Object
  • Object
show all
Defined in:
lib/relish/commands/dsl/help_text.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_commandObject

Returns the value of attribute current_command.



7
8
9
# File 'lib/relish/commands/dsl/help_text.rb', line 7

def current_command
  @current_command
end

.next_descriptionObject

Returns the value of attribute next_description.



7
8
9
# File 'lib/relish/commands/dsl/help_text.rb', line 7

def next_description
  @next_description
end

.next_usageObject

Returns the value of attribute next_usage.



7
8
9
# File 'lib/relish/commands/dsl/help_text.rb', line 7

def next_usage
  @next_usage
end

Class Method Details

.add(name, command) ⇒ Object



9
10
11
12
13
14
# File 'lib/relish/commands/dsl/help_text.rb', line 9

def add(name, command)
  self.current_command = name
  commands[command] = [] unless commands.key?(command)
  commands[command].push(get_next_usage => get_next_description)
  reset_accessors
end

.clear_commandsObject



34
35
36
# File 'lib/relish/commands/dsl/help_text.rb', line 34

def clear_commands
  @commands = {}
end

.commandsObject



26
27
28
# File 'lib/relish/commands/dsl/help_text.rb', line 26

def commands
  @commands ||= {}
end

.get_next_descriptionObject



20
21
22
23
24
# File 'lib/relish/commands/dsl/help_text.rb', line 20

def get_next_description
  next_description || raise(
    "please set a description for #{current_command.inspect}"
  )
end

.get_next_usageObject



16
17
18
# File 'lib/relish/commands/dsl/help_text.rb', line 16

def get_next_usage
  next_usage or current_command.to_s
end

.max_usage_lengthObject



38
39
40
41
42
# File 'lib/relish/commands/dsl/help_text.rb', line 38

def max_usage_length
  commands.values.map {|v|
    v.map {|v| v.keys.to_s.length }.max
  }.max
end

.reset_accessorsObject



30
31
32
# File 'lib/relish/commands/dsl/help_text.rb', line 30

def reset_accessors
  self.current_command = self.next_usage = self.next_description = nil
end