bin/soulmate in soulmate-0.0.4 vs bin/soulmate in soulmate-0.0.5
- old
+ new
@@ -25,23 +25,62 @@
exit
end
opts.separator ""
opts.separator "Commands:"
- opts.separator " load TYPE Loads items of specified type read from stdin in the JSON lines format"
+ opts.separator " load TYPE Replaces collection specified by TYPE with items read from stdin in the JSON lines format."
+ opts.separator " add TYPE Adds items to collection specified by TYPE read from stdin in the JSON lines format."
+ opts.separator " remove TYPE Removes items from collection specified by TYPE read from stdin in the JSON lines format. Items only require an 'id', all other fields are ignored."
+ opts.separator " query TYPE QUERY Queries for items from collection specified by TYPE."
end
def load(type)
puts "Loading items of type #{type}..."
- items = $stdin.read.split("\n").map { |l| JSON.parse(l) }
- total = Soulmate::Loader.new(type).load(items)
- puts "Loaded a total of #{total} items"
+ items = $stdin.read.split("\n").map { |l| MultiJson.decode(l) }
+ loaded = Soulmate::Loader.new(type).load(items)
+ puts "Loaded a total of #{loaded.size} items"
end
+def add(type)
+ puts "Adding items of type #{type}..."
+ loader = Soulmate::Loader.new(type)
+ items = $stdin.read.split("\n").map { |l| MultiJson.decode(l) }
+ items.each do |item|
+ loader.add(item)
+ end
+ puts "Loaded a total of #{items.size} items"
+end
+
+def remove(type)
+ puts "Removing items of type #{type}..."
+ loader = Soulmate::Loader.new(type)
+ items = $stdin.read.split("\n").map { |l| MultiJson.decode(l) }
+ items.each do |item|
+ loader.remove(item)
+ end
+ puts "Removed a total of #{items.size} items"
+end
+
+def query(type, query)
+ puts "> Querying '#{type}' for '#{query}'"
+ matcher = Soulmate::Matcher.new(type)
+ results = matcher.matches_for_term(query, :limit => 0)
+ results.each do |item|
+ puts MultiJson.encode(item)
+ end
+ puts "> Found #{results.size} matches"
+end
+
parser.parse!
case ARGV[0]
when 'load'
load ARGV[1]
+when 'add'
+ add ARGV[1]
+when 'remove'
+ remove ARGV[1]
+when 'query'
+ query ARGV[1], ARGV[2]
else
puts parser.help
end