organizing my thoughts

This commit is contained in:
Adam Sanderson 2010-08-05 17:49:12 -07:00
parent e6a23d045b
commit a809fcbdd5
2 changed files with 62 additions and 43 deletions

View File

@ -1,56 +1,75 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'optparse' require 'optparse'
puts "Qwandry; a qwestionable tool" # Informal Spec:
opts = OptionParser.new do |opts| #
opts.banner = "Usage: qwandry [options] [type] repository-name" # A User may have multiple Repositories
# A Repositories contains Packages
#
# A User will search for a repository giving a name and optional version
# Each Repository will be scanned for matching Packages
# If only one Package matches, that Package will be opened
# If more than one Package matches, then the user will be prompted to pick one
# While any two Packages share the same name their parent dir is appended
# If no Repository matches, then qwandry will exit with a -404 (repo not found)
#
module Qwandry
opts.separator "" class Repository
opts.separator "Known Repositories:" def initialize(path)
# ... @path = path.chomp('/')
end end
opts.parse! ARGV def scan(name)
[]
if ARGV.length != 1 end
puts opts
exit(-1)
end
##
class Repository
def initialize(path)
@path = path.chomp('/')
end end
def scan(name) # Directories look like:
[] # Repository
# lib-0.1
# lib-0.2
class FlatRepository < Repository
def scan(name)
Dir["#{@path}/*"].select{|path| path if File.basename(path).start_with?(name)}
end
end end
end end
class FlatRepository < Repository if __FILE__ == $0
def scan(name) opts = OptionParser.new do |opts|
Dir["#{@path}/*"].select{|path| path if File.basename(path).start_with?(name)} opts.banner = "Usage: qwandry [options] name [version]"
opts.separator ""
opts.separator "Known Repositories:"
# ...
end end
end
## opts.parse! ARGV
load('repositories.rb')
name = ARGV.pop if ARGV.length != 1
candidates = [] puts opts
exit(-1)
@repositories.each do |set, repos|
repos.each do |repo|
candidates.concat(repo.scan(name))
end end
end
candidates.each_with_index do |path, index| load('repositories.rb')
puts " #{index+1}. #{File.basename path}"
end
print ">> " name = ARGV.pop
index = gets.to_i-1 candidates = []
path = candidates[index]
`mate #{path}` @repositories.each do |set, repos|
repos.each do |repo|
candidates.concat(repo.scan(name))
end
end
candidates.each_with_index do |path, index|
puts " #{index+1}. #{File.basename path}"
end
print ">> "
index = gets.to_i-1
path = candidates[index]
`mate #{path}`
end

View File

@ -5,7 +5,7 @@ def which(bin)
end end
def add(label, path) def add(label, path)
@repositories[label.to_s] << FlatRepository.new(path) @repositories[label.to_s] << Qwandry::FlatRepository.new(path)
end end
if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby' if which('ruby') == '/Users/adam/.rvm/rubies/ruby-1.9.1-p378/bin/ruby'