Class: Wod::Command::Help

Inherits:
Base
  • Object
show all
Defined in:
lib/wod/commands/help.rb

Defined Under Namespace

Classes: HelpGroup

Instance Attribute Summary

Attributes inherited from Base

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #wod

Methods included from Helpers

#ask, #display_formatted, #error, #home_directory, #last_page_file, #wod_directory

Constructor Details

This class inherits a constructor from Wod::Command::Base

Class Method Details

.create_default_groups!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wod/commands/help.rb', line 31

def self.create_default_groups!
  return if @defaults_created
  @defaults_created = true
  group 'General Commands' do |group|
    group.command 'help',                         'show this usage'
    group.command 'version',                      'show the gem version'
    group.space
    group.command 'login',                        'log in with your apple credentials'
    group.command 'logout',                       'clear local authentication credentials'
    group.space
    group.command 'devices',                         'list your registered devices'
    group.command 'devices:add <name> <udid>',      'add a new device'
    group.command 'devices:remove <name>',      'remove device (Still counts against device limit)'
  end
end

.group(title, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/wod/commands/help.rb', line 23

def self.group(title, &block)
  groups << begin
    group = HelpGroup.new(title)
    yield group
    group
  end
end

.groupsObject



19
20
21
# File 'lib/wod/commands/help.rb', line 19

def self.groups
  @groups ||= []
end

Instance Method Details

#indexObject



47
48
49
# File 'lib/wod/commands/help.rb', line 47

def index
  puts usage
end

#usageObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/wod/commands/help.rb', line 51

def usage
  puts "wod v#{Wod::VERSION}"
  puts
  
  longest_command_length = self.class.groups.map do |group|
    group.map { |g| g.first.length }
  end.flatten.max
  
  self.class.groups.inject(StringIO.new) do |output, group|
    output.puts "=== %s" % group.title
    output.puts
  
    group.each do |command, description|
      if command.empty?
        output.puts
      else
        output.puts "%-*s # %s" % [longest_command_length, command, description]
      end
    end
  
    output.puts
    output
  end.string
end