Class: POEditor::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/poeditor/commands/command.rb

Class Method Summary collapse

Class Method Details

.check_updateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/poeditor/commands/command.rb', line 29

def self.check_update
  begin
    uri = URI("https://api.github.com"\
              "/repos/StyleShare/poeditor-cli/releases/latest")
    data = JSON(Net::HTTP.get(uri))
    latest = data["tag_name"]
    if Gem::Version.new(VERSION) < Gem::Version.new(latest)
      UI.puts %{\
poeditor-cli #{latest} is available. (You're using #{VERSION})
To update: `$ gem install poeditor-cli`
Changelog: https://github.com/StyleShare/poeditor-cli/releases\
      }.green
    end
  rescue
  end
end

.command_class(argv) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/poeditor/commands/command.rb', line 18

def self.command_class(argv)
  case argv[0]
  when "pull"
    PullCommand
  when "--version"
    VersionCommand
  else
    HelpCommand
  end
end

.run(argv) ⇒ Object

The entry point of the CLI application



7
8
9
10
11
12
13
14
15
16
# File 'lib/poeditor/commands/command.rb', line 7

def self.run(argv)
  UI.enabled = true
  self.check_update
  command = self.command_class(argv).new
  begin
    command.run(argv)
  rescue POEditor::Exception => e
    puts "[!] #{e.message}".red
  end
end