Class: Lingohub::Command::Help

Inherits:
Base
  • Object
show all
Defined in:
lib/lingohub/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, #lingohub, #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 Lingohub::Command::Base

Class Method Details

.create_default_groups!Object



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
65
66
# File 'lib/lingohub/commands/help.rb', line 34

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',                        "let's you (re)login"
    group.command 'logout',                       'logs you out by clearing your current credentials'
  end

  group 'Project Commands' do |group|
    group.command 'project:list',                         'list your projects'
    group.command 'project:open --project <name>',        'open the project in a web browser'
    group.space
  end

  group 'Translation Commands' do |group|
    group.command 'resource:down --all --directory <path> --project <name>',                                          'download all resource files'
    group.command 'resource:down --locale <iso2_code> --all --directory <path> --project <name>',                     'download all resource files, using the given locale as filter'
    group.command 'resource:down <file1> <file2> ... --directory <path> --project <name>',                            'download specific resource files'

    up_command = 'resource:up <file1> <file2> ... --locale <iso2_code> --project <name>'

    strategy_desc = ""
    Lingohub::Command::Resource::EXPECTED_STRATEGY_PARAMETERS.each do |parameter|
      strategy_desc << " --#{parameter} true|false"
    end

    group.command "resource:up <file1> <file2> ... --locale <iso2_code> --project <name> [#{strategy_desc}]",          "upload specific resource files, a locale may be specified to tell lingohub the locale of file content"
    group.space
  end
end

.group(title, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/lingohub/commands/help.rb', line 26

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

.groupsObject



22
23
24
# File 'lib/lingohub/commands/help.rb', line 22

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

Instance Method Details

#indexObject



68
69
70
# File 'lib/lingohub/commands/help.rb', line 68

def index
  display usage
end

#usageObject



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

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



72
73
74
# File 'lib/lingohub/commands/help.rb', line 72

def version
  display Lingohub::Client.version
end