92 lines
2.2 KiB
Ruby
Executable File
92 lines
2.2 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
# Add Qwandry's library to the load path
|
|
$:.unshift File.dirname(__FILE__) + '/../lib'
|
|
|
|
# Require Qwandry's library
|
|
require "qwandry.rb"
|
|
|
|
# Load Qwandry's configuration files
|
|
config = Qwandry::Configuration
|
|
config.load_configuration_files
|
|
|
|
# Create a launcher
|
|
@launcher = Qwandry::Launcher.new
|
|
|
|
opts = OptionParser.new do |opts|
|
|
opts.banner = "Usage: qwandry [options] name"
|
|
opts.separator ""
|
|
|
|
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
|
|
end
|
|
|
|
opts.separator ""
|
|
opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor|
|
|
@launcher.editor = editor
|
|
end
|
|
|
|
opts.separator "Additional Commands"
|
|
|
|
opts.on("--customize", "Create and edit files for customizing Qwandry") do
|
|
dir = Qwandry.config_dir
|
|
if !dir
|
|
puts "HOME directory must be defined."
|
|
exit(1)
|
|
else
|
|
FileUtils.mkdir_p(dir, :verbose=>true) unless File.exist?(dir)
|
|
Dir[File.dirname(__FILE__) + '/../templates/*'].each do |path|
|
|
FileUtils.cp(path, dir, :verbose=>true) unless File.exist?(path)
|
|
end
|
|
@launcher.launch dir
|
|
end
|
|
exit(0)
|
|
end
|
|
|
|
opts.on_tail("-h", "--help", "Show this message") do
|
|
puts opts
|
|
exit
|
|
end
|
|
end
|
|
|
|
opts.parse! ARGV
|
|
if ARGV.length == 0
|
|
puts opts
|
|
exit 1
|
|
end
|
|
|
|
# Find the packages:
|
|
name = ARGV.join(' ')
|
|
packages = @launcher.find(*ARGV)
|
|
ARGV.clear # for the gets below
|
|
|
|
# There may be 0, 1, or many matches. If many, then
|
|
# ask the user which one to launch.
|
|
package = nil
|
|
case packages.length
|
|
when 0
|
|
puts "No packages matched '#{name}'"
|
|
exit 4 # Exit code 4 for No Package
|
|
when 1
|
|
package = packages.first
|
|
else
|
|
packages.each_with_index do |package, index|
|
|
puts "%3d. %s" % [index+1, package.name]
|
|
end
|
|
|
|
print ">> "
|
|
index = gets.to_i - 1
|
|
package = packages[index]
|
|
end
|
|
|
|
# If there is a package, then launch it.
|
|
if package
|
|
if @launcher.launch(package)
|
|
# Exit code 0 for success
|
|
exit 0
|
|
else
|
|
# Exit with the status returned by the process used to open the package
|
|
exit $?.exitstatus
|
|
end
|
|
end
|