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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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' 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
97 98 99 100 101 102 103 104 105 |
# File 'lib/raykit/console.rb', line 97 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
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/raykit/console.rb', line 83 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/raykit/console.rb', line 107 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
27 28 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 |
# File 'lib/raykit/console.rb', line 27 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 |
#work(hash) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/raykit/console.rb', line 130 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 |