Class: Raykit::Console
- Inherits:
-
Object
- Object
- Raykit::Console
- Defined in:
- lib/raykit/console.rb
Overview
The implementation for the raykit console application
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #import(hash) ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #list(hash) ⇒ Object
- #rake(hash) ⇒ Object
- #run ⇒ Object
- #work(hash) ⇒ Object
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/raykit/console.rb', line 10 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' o.bool '-q','--quiet','enable quiet mode' o.bool -'l','--list','list names' o.bool -'c','--clean','clean work directories' end if(opts.verbose?) puts "options: " + Rainbow(@opts.to_hash).yellow.bright end end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
9 10 11 |
# File 'lib/raykit/console.rb', line 9 def opts @opts end |
Instance Method Details
#import(hash) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/raykit/console.rb', line 101 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 |
#list(hash) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/raykit/console.rb', line 87 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 |
#rake(hash) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/raykit/console.rb', line 111 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 |
#run ⇒ Object
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/raykit/console.rb', line 30 def run if(ARGV.length == 0) puts @opts 0 else if(@opts.verbose?) selected_repositories = REPOSITORIES.select{|r| r.include?(@opts[:remote])} if(selected_repositories.length == 0) puts "no matching remotes" return else puts "matching remotes:" selected_repositories.each{|r| puts r} end end 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 if(@opts.clean?) if(Dir.exists(work.directory)) puts 'removing ' + Rainbow(work.directory).yellow FileUtils.remove_dir(work.directory) end end } end end |
#work(hash) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/raykit/console.rb', line 134 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 |