Class: Aurb::Main
- Inherits:
-
Thor
- Object
- Thor
- Aurb::Main
- Defined in:
- lib/aurb/main.rb
Constant Summary collapse
- ARGV =
::ARGV.dup
Instance Method Summary collapse
- #download(*pkgs) ⇒ Object
- #info(pkg) ⇒ Object
- #search(*pkgs) ⇒ Object
- #upgrade ⇒ Object
- #version ⇒ Object
Instance Method Details
#download(*pkgs) ⇒ Object
25 26 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 |
# File 'lib/aurb/main.rb', line 25 def download(*pkgs) pkgs = Aurb.download(*pkgs) raise Aurb::NoResultsError if pkgs.empty? path = if .path.start_with?('/') .path else File.join(Dir.pwd, .path) end if File.exist?(path) path = File.(path) else raise Aurb::DownloadError, "'#{path}' is not a valid path" end pkgs.each_with_index do |package, index| local = package.split('/')[-1] Dir.chdir path do open package do |remote| File.open local, 'wb' do |local| local.write remote.read end end Archive::Tar::Minitar. unpack Zlib::GzipReader.new(File.open(local, 'rb')), Dir.pwd File.delete local unless .keep? end puts "(#{index+1}/#{pkgs.size}) downloaded #{local}" end end |
#info(pkg) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/aurb/main.rb', line 76 def info(pkg) info = Aurb.info(pkg) raise Aurb::NoResultsError if info.empty? info.each do |key, value| (key.size..10).each { print ' ' } print key.colorize(:yellow) + ' ' puts value end end |
#search(*pkgs) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/aurb/main.rb', line 61 def search(*pkgs) pkgs = Aurb.search(*pkgs) raise Aurb::NoResultsError if pkgs.empty? pkgs.each do |package| status = package.OutOfDate == '1' ? '✘'.colorize(:red) : '✔'.colorize(:green) name, version, description, votes = package.Name.colorize(:yellow), package.Version, package.Description, package.NumVotes.colorize(:blue) puts "[#{status}] #{name} #{version} (#{votes})\n #{description}" end end |
#upgrade ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/aurb/main.rb', line 88 def upgrade list = `pacman -Qm`.split(/\n/) pkgs = Aurb.upgrade(*list) raise Aurb::NoResultsError if pkgs.empty? pkgs.each do |package| puts "#{package.to_s.colorize(:yellow)} has an upgrade available" end end |
#version ⇒ Object
99 100 101 102 103 104 |
# File 'lib/aurb/main.rb', line 99 def version require 'aurb/version' require 'thor/version' puts "Aurb v#{Aurb::VERSION} - Thor v#{Thor::VERSION}" puts 'Copyright (c) 2009-2010 Gigamo <[email protected]>' end |