Class: Squidward::Command::Help

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

Defined Under Namespace

Classes: HelpGroup

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#configuration, #display, #logger, #store_configuration

Class Method Details

.create_default_groups!Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/squidward/commands/help.rb', line 32

def self.create_default_groups!
  group 'General Commands' do |group|
    group.command 'help',                             'show this usage'
    group.command 'version',                          'show gem version'
    group.space
    group.command 'bucket:set <name>',                'set the S3 bucket where the files will be uploaded (default: backup, created when missing)'
    group.space
    group.command 'credentials:clear',                'clear the credentials stored on your settings'
    group.space
    group.command 'domain:backup <domain> [vpath] ',  'add aws_simpledb domain for backup [optional vpath a virtual path inside the bucket]'
    group.command 'domain:remove <domain>',           'remove aws_simpledb domain from backup list'
    group.space
    group.command 'run',                              'run the process by taking one by one the domains configured on your settings'        
    group.space
    group.command 'info',                             'display your current settings'
    group.command 'logs',                             'display lastest information from the log file'
  end
end

.group(title, &block) ⇒ Object



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

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

.groupsObject



20
21
22
# File 'lib/squidward/commands/help.rb', line 20

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

Instance Method Details

#index(args) ⇒ Object



51
52
53
# File 'lib/squidward/commands/help.rb', line 51

def index(args)
  display usage
end

#usageObject



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

def usage
  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