#!/usr/bin/ruby $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'arson' require 'arson/colorful' require 'optparse' Arson::Config.write unless File.exists? Arson::Config::FILE_PATH options = {:download => 0} opts = OptionParser.new do |opts| opts.banner = "Usage: arson [options]" opts.on("-d", "--download", "Download the exact package name", "Repeating this will download other depenedencies in AUR") do options[:download] += 1 end opts.on("-u", "--upgrade", "Check for upgrades") do options[:upgrade] = true end opts.on_tail("-h", "--help", "Show this message") do puts opts exit 0 end opts.on_tail("--version", "Show version") do puts "arson v#{Arson::VERSION.join('.')}" puts "Copyright (C) 2008 Colin Shea " puts "Licensed under the GPLv3, all rights reserved" exit 0 end end ARGV.empty? ? opts.parse!(["-h"]) : opts.parse!(ARGV) if options[:download] > 0 and ARGV.empty? warn "Missing names of packages to download!" exit 1 end if options[:upgrade] print "Checking for upgrades..." $stdout.flush upgrades = Arson.check_upgrades unless upgrades.empty? print "\n" $stdout.flush upgrades.each do |line, new_version| puts "#{line.strip} #{Arson.colorful("Green", new_version)}" end else puts "Nothing to update" end exit 0 elsif options[:download] > 0 exit_code = 0 ARGV.each do |pkg| if pkg = Arson.find_exact(pkg) puts "Downloading #{pkg['Name']}..." Arson.download(pkg) else warn "No such package '#{pkg}'" exit_code = 1 end end exit exit_code end packages = Arson.search(ARGV) if packages.length > 1 packages.each do |pkg| name = Arson.colorful("White", pkg['Name']) name = Arson.colorful("Red", name) if pkg["OutOfDate"] == "1" if Arson::Categories[pkg['CategoryID'].to_i] && Arson::Categories[pkg['CategoryID'].to_i] != "nil" category = "-#{Arson::Categories[pkg['CategoryID'].to_i]}" else category = "" end puts <<-HERE #{Arson.colorful("Magenta", "aur#{category}")}/#{name} #{Arson.colorful("Green",pkg['Version'])} #{pkg['Description']} HERE $stdout.flush end elsif packages.length == 1 puts "Downloading #{packages.first['Name']}..." Arson.download(packages.first) exit 0 end if Arson::Config["run-pacman"] if File.exists? "/usr/bin/pacman-color" and Arson::Config["color"] exec "/usr/bin/pacman-color -Ss #{ARGV.join(' ')}" else exec "/usr/bin/pacman -Ss #{ARGV.join(' ')}" end end