/
app.rb
63 lines (50 loc) · 1.02 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'readline'
module Space
class App
class << self
attr_reader :config
def run(name)
@config = Config.load(name)
new(config.name || name).run
end
end
include Readline
attr_accessor :screen, :name, :repos, :bundle, :path
def initialize(name)
@screen = Screen.new(self)
@name = name
@bundle = Bundle.new(self.class.config.paths.first)
@path = File.expand_path('.')
end
def prompt
# "#{repos.name} >".strip + ' '
'> '
end
def repos
@repos ||= Repos.all
end
def run
screen.render
loop do
line = readline(prompt, true)
break if line.nil?
handle(line) unless line.empty?
end
puts
end
def handle(line)
Action.run(self, line)
screen.render
end
def reset
bundle.reset
repos.each(&:reset)
end
def execute(cmd)
chdir { system(cmd) }
end
def chdir(&block)
Dir.chdir(path, &block)
end
end
end