Created
December 2, 2015 13:53
-
-
Save myokoym/5d9fdc3654a280d6c33c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "readline" | |
require "tempfile" | |
if ARGV.size < 2 | |
$stderr.puts("Usage: #{$0} GROONGA_EXE DB_PATH") | |
exit(1) | |
end | |
groonga_exe = ARGV.shift | |
db_path = ARGV.shift | |
basename = File.basename(db_path) | |
while line = Readline.readline("groonga(#{basename})> ", true) | |
pretty_print = false | |
case line | |
when "quit" | |
break | |
when /\App / | |
pretty_print = true | |
line = line[3..-1] | |
end | |
Tempfile.open(['readliroonga', '.grn']) do |file| | |
file.write(line) | |
file.flush | |
response = `#{groonga_exe} #{db_path} < #{file.path}` | |
if pretty_print | |
require "json" | |
puts jj(JSON.parse!(response)) | |
else | |
puts response | |
end | |
end | |
end | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment