2010-08-18 04:42:57 +00:00
|
|
|
#!/usr/bin/env ruby
|
2010-12-30 16:56:16 +00:00
|
|
|
|
|
|
|
# Add Qwandry's library to the load path
|
2010-11-09 06:31:09 +00:00
|
|
|
$:.unshift File.dirname(__FILE__) + '/../lib'
|
2010-12-30 16:56:16 +00:00
|
|
|
|
|
|
|
# Require Qwandry's library
|
2010-11-09 06:31:09 +00:00
|
|
|
require "qwandry.rb"
|
2010-08-18 04:42:57 +00:00
|
|
|
|
2010-12-30 16:56:16 +00:00
|
|
|
# Load Qwandry's configuration files
|
|
|
|
config = Qwandry::Configuration
|
|
|
|
config.load_configuration_files
|
|
|
|
|
|
|
|
# Create a launcher
|
|
|
|
@launcher = Qwandry::Launcher.new
|
2010-08-18 04:42:57 +00:00
|
|
|
|
|
|
|
opts = OptionParser.new do |opts|
|
2010-11-09 03:39:00 +00:00
|
|
|
opts.banner = "Usage: qwandry [options] name"
|
2010-08-18 04:42:57 +00:00
|
|
|
opts.separator ""
|
|
|
|
|
2010-12-30 16:56:16 +00:00
|
|
|
opts.on("-r", "--repo LABELS", Array, "Search in LABELS, default: #{config.default.join(',')}","Available Repository Types:", *config.configurations.map{|c| " #{c}"}) do |names|
|
|
|
|
config.default *names
|
2010-11-09 03:39:00 +00:00
|
|
|
end
|
2010-11-09 06:31:09 +00:00
|
|
|
|
2010-11-10 08:26:26 +00:00
|
|
|
opts.separator ""
|
2010-08-18 04:42:57 +00:00
|
|
|
opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor|
|
2010-12-30 16:56:16 +00:00
|
|
|
@launcher.editor = editor
|
2010-08-18 04:42:57 +00:00
|
|
|
end
|
|
|
|
|
2010-11-11 03:38:20 +00:00
|
|
|
opts.separator "Additional Commands"
|
|
|
|
|
2010-11-14 23:42:06 +00:00
|
|
|
opts.on("--customize", "Create and edit files for customizing Qwandry") do
|
2010-12-09 03:46:59 +00:00
|
|
|
dir = Qwandry.config_dir
|
2010-11-14 23:42:06 +00:00
|
|
|
if !dir
|
2010-12-09 03:46:59 +00:00
|
|
|
puts "HOME directory must be defined."
|
2010-11-14 23:42:06 +00:00
|
|
|
exit(1)
|
|
|
|
else
|
2010-12-11 21:57:28 +00:00
|
|
|
FileUtils.mkdir_p(dir, :verbose=>true) unless File.exist?(dir)
|
2010-11-14 23:42:06 +00:00
|
|
|
Dir[File.dirname(__FILE__) + '/../templates/*'].each do |path|
|
2010-12-11 21:57:28 +00:00
|
|
|
FileUtils.cp(path, dir, :verbose=>true) unless File.exist?(path)
|
2010-11-14 23:42:06 +00:00
|
|
|
end
|
2010-12-30 16:56:16 +00:00
|
|
|
@launcher.launch dir
|
2010-11-14 23:42:06 +00:00
|
|
|
end
|
2010-11-14 21:39:28 +00:00
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
|
2010-08-18 04:42:57 +00:00
|
|
|
opts.on_tail("-h", "--help", "Show this message") do
|
|
|
|
puts opts
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.parse! ARGV
|
2010-11-19 23:01:28 +00:00
|
|
|
if ARGV.length == 0
|
2010-08-18 04:42:57 +00:00
|
|
|
puts opts
|
2010-12-29 16:01:18 +00:00
|
|
|
exit 1
|
2010-08-18 04:42:57 +00:00
|
|
|
end
|
|
|
|
|
2010-12-30 16:56:16 +00:00
|
|
|
# Find the packages:
|
2010-11-19 23:01:28 +00:00
|
|
|
name = ARGV.join(' ')
|
2010-12-30 16:56:16 +00:00
|
|
|
packages = @launcher.find(*ARGV)
|
2010-11-19 23:01:28 +00:00
|
|
|
ARGV.clear # for the gets below
|
2010-08-18 04:42:57 +00:00
|
|
|
|
2010-12-30 16:56:16 +00:00
|
|
|
# There may be 0, 1, or many matches. If many, then
|
|
|
|
# ask the user which one to launch.
|
2010-08-18 04:42:57 +00:00
|
|
|
package = nil
|
|
|
|
case packages.length
|
|
|
|
when 0
|
|
|
|
puts "No packages matched '#{name}'"
|
2010-12-29 16:01:18 +00:00
|
|
|
exit 4 # Exit code 4 for No Package
|
2010-08-18 04:42:57 +00:00
|
|
|
when 1
|
|
|
|
package = packages.first
|
|
|
|
else
|
|
|
|
packages.each_with_index do |package, index|
|
|
|
|
puts "%3d. %s" % [index+1, package.name]
|
|
|
|
end
|
|
|
|
|
|
|
|
print ">> "
|
2010-11-19 23:01:28 +00:00
|
|
|
index = gets.to_i - 1
|
2010-08-18 04:42:57 +00:00
|
|
|
package = packages[index]
|
|
|
|
end
|
|
|
|
|
2010-12-30 16:56:16 +00:00
|
|
|
# If there is a package, then launch it.
|
2010-12-29 10:57:14 +00:00
|
|
|
if package
|
2010-12-30 16:56:16 +00:00
|
|
|
if @launcher.launch(package)
|
2010-12-29 16:01:18 +00:00
|
|
|
# Exit code 0 for success
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
# Exit with the status returned by the process used to open the package
|
|
|
|
exit $?.exitstatus
|
2010-12-29 10:57:14 +00:00
|
|
|
end
|
|
|
|
end
|