bin/arson in evaryont-arson-2.0.2 vs bin/arson in evaryont-arson-2.1.1
- old
+ new
@@ -2,51 +2,72 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'arson'
require 'arson/colorful'
+require 'optparse'
+Arson::Config.write unless File.exists? Arson::Config::FILE_PATH
-if ARGV.to_s == ""
- puts "arson #{Arson::VERSION.join('.')} [Colin 'Evaryont' Shea <evaryont@saphrix.com>]"
- puts "Please specifiy what to search for as the parameters to this script:"
- puts Arson.colorful(:italic, " #{Arson::PROGRAM} pacman")
- puts ""
- puts "If you want to download a package, run #{Arson::PROGRAM} as such:"
- puts Arson.colorful(:italic, " #{Arson::PROGRAM} aur/arson")
- puts "(note: you can include the -category bit if you wish)"
- puts ""
- puts "Passing '?' to arson will cause it to check for any upgrades"
- exit 1
-end
+options = {:download => 0}
+opts = OptionParser.new do |opts|
+ opts.banner = "Usage: arson [options]"
-# Old regexp /^aur(?:-.*)\/(.*)$/
-if pkg = ARGV.to_s.scan(/aur(-.*?)?\/(.*)/i).flatten[1]
- if pkg = Arson.find_exact(pkg)
- puts "Downloading #{pkg['Name']}..."
- Arson.download(pkg)
+ 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
- else
- warn "I think you attempted to download a package, but I couldn't find it"
+ end
+
+ opts.on_tail("--version", "Show version") do
+ puts "arson v#{Arson::VERSION.join('.')}"
+ puts "Copyright (C) 2008 Colin Shea <colin@evaryont.me>"
+ puts "Licensed under the GPLv3, all rights reserved"
exit 0
end
+
end
+ARGV.empty? ? opts.parse!(["-h"]) : opts.parse!(ARGV)
-if ARGV.to_s =~ /\?/
+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::ASCII_CHECK} #{Arson.colorful("Green", 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|
@@ -68,10 +89,12 @@
puts "Downloading #{packages.first['Name']}..."
Arson.download(packages.first)
exit 0
end
-if File.exists? "/usr/bin/pacman-color"
- exec "/usr/bin/pacman-color -Ss #{ARGV.join(' ')}"
-else
- exec "/usr/bin/pacman -Ss #{ARGV.join(' ')}"
+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