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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/raykit/console.rb', line 9 def initialize @opts = Slop.parse do |o| o.string '-r', '--remote', 'remote name or substring', default: '' o.string '-t','--task','rake task', default: 'default' o.string '-l','--level','log level (debug,info,warn,error)', default: 'info' #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 -'s','--show','show 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.
8 9 10 |
# File 'lib/raykit/console.rb', line 8 def opts @opts end |
Instance Method Details
#import(hash) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/raykit/console.rb', line 120 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
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/raykit/console.rb', line 106 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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/raykit/console.rb', line 130 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
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/raykit/console.rb', line 29 def run if(ARGV.length == 0) puts @opts 0 else # align log level with @opts[:level] LOG.set_severity_as_string(@opts[:level]) if(LOG.severity == Logger::Severity::DEBUG || LOG.severity == Logger::Severity::INFO) puts '--remote = ' + @opts[:remote] puts '--task = ' + @opts[:task] puts '--level = ' + @opts[:level] 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.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?) # do not pull if the working directory does not already exist. if(Dir.exists?(repo.get_dev_dir('work'))) work.pull end 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.exist?(work.directory)) puts 'removing ' + Rainbow(work.directory).yellow FileUtils.remove_dir(work.directory) end end } end end |
#work(hash) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/raykit/console.rb', line 153 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 |