class Raykit::Console
The implementation for the raykit console application
def import(hash)
def import(hash) pattern='' pattern=hash["pattern"] if(hash.include?("pattern")) puts 'scanning...' count=REPOSITORIES.length REPOSITORIES.import(pattern) new_count=REPOSITORIES.length-count puts "imported #{new_count} git repositories" end
def initialize
def initialize @opts = Slop.parse do |o| o.string '-r', '--remote', 'remote name or substring', default: '' #o.string '-b', '--branch','branch name' o.string '-t','--task','rake task', default: 'default' o.bool '-v', '--verbose', 'enable verbose mode' o.bool '-i','--import','import remotes from work directory' o.bool '-p','--pull','pull work directory' o.bool '-w','--work','rake work directory' o.bool '-m','--make','make latest commit' end if(opts.verbose?) puts "options: " + Rainbow(@opts.to_hash).yellow.bright end end
def list(hash)
def list(hash) pattern='' if(hash.include?(:pattern)) pattern=hash["pattern"] end pattern='' if(pattern.nil?) REPOSITORIES.each{|url| if(url.include?(pattern)) puts Rainbow(url).yellow.bright end } end
def rake(hash)
def rake(hash) REPOSITORIES.each{|remote| if(remote.include?(hash[:pattern])) begin puts "remote: #{remote}" cmd = Raykit::Rake::run(remote,'master') elapsed_str = Timer.get_elapsed_str(cmd.elapsed) if(cmd.exitstatus == 0) puts elapsed_str + " " + Rainbow(cmd.command).yellow.bright + " (#{cmd.directory})" else puts "\r\n" + cmd.command + "\r\n" puts "\r\n" + cmd.output + "\r\n" puts "\r\n" + cmd.error + "\r\n" puts '' puts Rainbow(elapsed_str).red.bright + " " + Rainbow(cmd.command).white end rescue puts 'rescued...' end end } end
def run
def run if(ARGV.length == 0) puts @opts 0 else if(@opts.import?) puts Rainbow('import').yellow.bright puts "scanning #{REPOSITORIES.work_dir} for .git directories" count=REPOSITORIES.length REPOSITORIES.import(@opts[:remote]) new_count=REPOSITORIES.length-count puts "imported #{new_count} remotes" return 0 end REPOSITORIES.select{|r| r.include?(@opts[:remote])}.each{|remote| repo=Raykit::Git::Repository.new(remote) work=Raykit::Git::Directory.new(repo.get_dev_dir('work')) make=Raykit::Git::Directory.new(repo.get_dev_dir('make')) puts Rainbow(remote).green.bright if(@opts.pull?) work.pull end if(@opts.work?) if(!Dir.exist?(work.directory)) puts "work directory #{work.directory} does not exist, cloning" if(@opts.verbose?) puts `git clone #{remote} #{work.directory}` end puts "rake #{@opts[:task]} in #{work.directory}" if(@opts.verbose?) work.rake(@opts[:task]) end if(@opts.make?) if(!Dir.exist?(make.directory)) puts `git clone #{remote} #{make.directory}` end make.rake(@opts[:task]) end } #hash = Parser.parse ARGV #if(hash.include?(:verb)) # verb = hash[:verb] # case verb # when 'list' # list(hash) # when 'import' # import(hash) # when 'rake' # rake(hash) # when 'work' # work(hash) # end #end end end
def work(hash)
def work(hash) REPOSITORIES.each{|remote| if(remote.include?(hash[:pattern])) puts "remote: #{remote}" repo=Raykit::Git::Repository.new(remote) work=Raykit::Git::Directory.new(repo.get_dev_dir('work')) if(!Dir.exist?(work.directory)) Raykit::run("git clone #{remote} #{work.directory}") end work.rake('default') end } end