lib/space/app.rb in space-0.0.3 vs lib/space/app.rb in space-0.0.4
- old
+ new
@@ -1,72 +1,60 @@
require 'readline'
module Space
class App
- class << self
- attr_reader :instance
+ autoload :Command, 'space/app/command'
+ autoload :Handler, 'space/app/handler'
+ autoload :Logger, 'space/app/logger'
+ autoload :Parser, 'space/app/parser'
- def run(name)
- @instance = new(name)
- instance.run
+ class << self
+ def logger
+ @logger ||= Logger.new
end
-
- def name
- instance.name
- end
-
- def config
- instance.config
- end
end
include Readline
- attr_accessor :screen, :name, :config, :repos, :bundle, :path
+ attr_reader :name, :project, :screen
def initialize(name)
- @screen = Screen.new(self)
- @name = name
- @config = Config.load(name)
- @bundle = Bundle.new(config.paths.first)
- @path = File.expand_path('.')
- end
+ @name = name
+ @project = Models::Project.new(name)
+ @screen = Screen.new(project)
- def prompt
- # "#{repos.name} >".strip + ' '
- '> '
+ project.subscribe(screen)
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
+ refresh
+ screen.display(:dashboard)
+ cli_loop
end
- def handle(line)
- Action.run(self, line)
- screen.render
- end
+ private
- def reset
- bundle.reset
- repos.each(&:reset)
- end
+ def refresh
+ screen.display(:progress)
+ project.refresh
+ end
- def execute(cmd)
- chdir { system(cmd) }
- end
+ def cli_loop
+ loop do
+ line = readline(prompt, true)
+ break if line.nil?
+ handle(line) unless line.empty?
+ end
+ end
- def chdir(&block)
- Dir.chdir(path, &block)
- end
+ def handle(line)
+ screen.display(:progress)
+ Handler.new(project).run(line)
+ screen.display(:dashboard)
+ end
+
+ def prompt
+ "#{project.repos.scoped? ? project.repos.scope.map { |r| r.name }.join(', ') : project.name} > "
+ end
end
end