2010-08-18 04:42:57 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# Add qwandry's library to the load path
|
2010-11-09 06:31:09 +00:00
|
|
|
$:.unshift File.dirname(__FILE__) + '/../lib'
|
2010-08-18 04:42:57 +00:00
|
|
|
# Require it
|
2010-11-09 06:31:09 +00:00
|
|
|
require "qwandry.rb"
|
2010-08-18 04:42:57 +00:00
|
|
|
|
2010-11-10 17:24:23 +00:00
|
|
|
# Create launcher
|
|
|
|
@qwandry = 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-11-11 02:56:30 +00:00
|
|
|
opts.on("-r", "--repo LABELS", Array, "Search in LABELS, default: #{@qwandry.active.to_a.join(',')}","Available Repositories:", *@qwandry.repositories.keys.map{|k| " #{k}"}) do |labels|
|
|
|
|
@qwandry.active.replace(labels)
|
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-11-09 06:31:09 +00:00
|
|
|
@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 21:39:28 +00:00
|
|
|
opts.on("--paths", "Prints all repositories and their paths") do
|
2010-11-11 03:38:20 +00:00
|
|
|
@qwandry.repositories.each do |label, entries|
|
2010-11-14 21:39:28 +00:00
|
|
|
puts "#{label} #{"[default]" if @qwandry.active.include? label}"
|
2010-11-11 03:38:20 +00:00
|
|
|
entries.each do |repo|
|
|
|
|
puts "\t#{repo.path} (#{repo.class.to_s.split('::').last})"
|
|
|
|
end
|
|
|
|
puts ""
|
|
|
|
end
|
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
|
2010-11-14 23:42:06 +00:00
|
|
|
opts.on("--customize", "Create and edit files for customizing Qwandry") do
|
|
|
|
dir = ENV['HOME'] && ENV['HOME'] + '/.qwandry/'
|
|
|
|
if !dir
|
|
|
|
puts "Home directory must be defined."
|
|
|
|
exit(1)
|
|
|
|
else
|
|
|
|
FileUtils.mkdir(dir, :verbose=>true) unless File.exist?(dir)
|
|
|
|
Dir[File.dirname(__FILE__) + '/../templates/*'].each do |path|
|
|
|
|
FileUtils.cp(path, dir, :verbose=>true, :preserve=>true)
|
|
|
|
end
|
|
|
|
@qwandry.launch dir
|
|
|
|
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
|
|
|
|
if ARGV.length != 1
|
|
|
|
puts opts
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
2010-11-09 06:31:09 +00:00
|
|
|
# Configure default values
|
|
|
|
@qwandry.editor = @editor if @editor
|
|
|
|
|
2010-08-18 04:42:57 +00:00
|
|
|
name = ARGV.pop
|
2010-11-11 02:56:30 +00:00
|
|
|
packages = @qwandry.find(name)
|
2010-08-18 04:42:57 +00:00
|
|
|
|
|
|
|
package = nil
|
|
|
|
case packages.length
|
|
|
|
when 0
|
|
|
|
puts "No packages matched '#{name}'"
|
|
|
|
exit 404 # Package not found -- hehe, super lame.
|
|
|
|
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
|
|
|
|
|
|
|
|
@qwandry.launch(package) if package
|