Sha256: 1b3937ab9fdfcad2ee19f121bcbd777aecf61a981c3618e7917a045c20543018

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

class Nachos
  class Main
    extend Forwardable
    include Nachos::Github
    def_delegators :cli, :shell, :dry_run?
    def_delegators :config, :config
    attr_reader :cli, :config
    
    def initialize(cli)
      @cli = cli
      @config = Nachos::Config.new
    end
    
    def info
%[You are running Nachos #{Nachos::VERSION} as #{github_user}.
#{github_summary}
Current configuration: #{config.display_config}]
    end
    
    def sync
      chdir config.repo_root do
        watched.each { |repo| sync_repo(repo) }
      end
    end
    
    def chdir(dir)
      shell.say_status :inside, dir
      if dry_run?
        yield
      else
        FileUtils.mkdir_p(dir) unless File.exist?(dir)
        FileUtils.cd(dir) { yield }
      end
    end
    
    def sync_repo(repo)
      git_url = repo.url.gsub("https", "git")
      path = repo_path(repo)
      if repo_exists?(repo)
        chdir(path) do
          run Hub("fetch").command
        end
      else
        run Hub("clone #{git_url} #{repo.owner}-#{repo.name}").command
      end
    end
    
    def repo_path(repo)
      Pathname(config.repo_root.join("#{repo.owner}-#{repo.name}"))
    end
    
    def repo_exists?(repo)
      repo_path(repo).directory?
    end
    
    def Hub(args)
      Hub::Runner.new(*args.split(' '))
    end
    
    def run(cmd)
      if dry_run?
        shell.say cmd
      else
        system cmd
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nachos-0.0.6 lib/nachos/main.rb
nachos-0.0.5 lib/nachos/main.rb