Class: Shelltoad::Command

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

Class Method Summary collapse

Class Method Details

.run(command, *args) ⇒ Object

API



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shelltoad/command.rb', line 11

def run(command, *args)
  case command.to_s
  when "-h", "--help", "help", "h"
    display_help
  when "errors", "ers", nil, ""
    Error.all.each do |error|
      output error.to_s
    end
  when "error", "er", "show", "sh"
    magic_find(args.shift) do |error|
      output error.view
    end
  when "commit", "ci"
    commit(*args)
  when "resolve", "rv"
    magic_find(args.shift) do |error|
      error.resolve!
      output "Error #{error.id} marked as resolved"
    end
  when "open", "op"
    magic_find(args.shift) do |error|
      open error.url
    end
  when /^[\d]/
    magic_find(command) do |error|
      open error.url
    end
  else
    raise BaseException, "Command not found"
  end
  return 0
rescue BaseException => e
  output e.message
  return 1
end