Class: Linguist::Command::Help

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

Defined Under Namespace

Classes: HelpGroup

Instance Attribute Summary

Attributes inherited from Base

#args, #autodetected_app

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#app_urls, #escape, #extract_app_from_git_config, #extract_option, #extract_project_title_from_args, #extract_project_title_from_dir_name, #extract_project_title_from_git, #git_remotes, #git_url, #initialize, #linguist, #project, #project_title

Methods included from Helpers

#ask, #confirm, #confirm_command, #deprecate, #display, #error, #format_date, #git, #has_git?, #home_directory, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #shell

Constructor Details

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

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/linguist_ruby/commands/help.rb', line 32

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
  end

  group 'Project Commands' do |group|
    group.command 'project:list',                         'list your projects'
    group.command 'project:create <name>',                'create a new project'
    group.command 'project:info <name>',                  'show project info, like web url and number of translations'
    group.command 'project:open <name>',                  'open the project in a web browser'
    group.command 'project:rename <oldname> <newname>',   'rename the project'
    group.command 'project:destroy <name',                'destroy the project permanently'
    group.space
  end

  group 'Collaborator Commands' do |group|
    group.command 'collaborator:list',           'list project collaborators'
    group.command 'collaborator:invite <email>', 'invite the collaborator'
    group.command 'collaborator:remove <email>', 'remove the collaborator'
    group.space
  end

  group 'Translation Commands' do |group|
    group.command 'translation:down --all --directory <path>',                 'download all resource files'
    group.command 'translation:down <file1> <file2> ... --directory <path>',   'download specific resource files'
    group.command 'translation:up <file1> <file2> ... --locale <iso2_slug>',   'upload specific resource files'
    group.space
  end
end

.group(title, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/linguist_ruby/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/linguist_ruby/commands/help.rb', line 20

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

Instance Method Details

#indexObject



66
67
68
# File 'lib/linguist_ruby/commands/help.rb', line 66

def index
  display usage
end

#usageObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/linguist_ruby/commands/help.rb', line 74

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

#versionObject



70
71
72
# File 'lib/linguist_ruby/commands/help.rb', line 70

def version
  display Linguist::Client.version
end