exe/solr_wrapper in solr_wrapper-0.11.0 vs exe/solr_wrapper in solr_wrapper-0.12.0
- old
+ new
@@ -3,12 +3,18 @@
require 'solr_wrapper'
require 'optparse'
options = {}
collection_options = {}
+subtext = <<HELP
+Commonly used command are:
+ clean : cleans all data from solr and configures a clean instance based on configuration options
+See 'solr_wrapper COMMAND --help' for more information on a specific command.
+HELP
+
args = OptionParser.new do |opts|
- opts.banner = "Usage: solr_wrapper [options]"
+ opts.banner = "Usage: solr_wrapper [options] subcommand"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
@@ -57,13 +63,27 @@
end
opts.on("--no-checksum", "Skip running checksum validation on the downloaded file") do |d|
options[:ignore_md5sum] = true
end
+
+ opts.separator ""
+ opts.separator subtext
end
+
+subcommands = {
+ 'clean' => OptionParser.new do |opts|
+ opts.banner = "Usage: clean"
+ end,
+}
+
+
begin
+ args.order!
+ command = ARGV.shift
+ subcommands[command].order! if command
args.parse!
rescue => error
$stderr.puts "ERROR: #{error}\n"
$stderr.puts args.help
exit 1
@@ -71,9 +91,20 @@
# default to verbose
options[:verbose] = true if options[:verbose].nil?
instance = SolrWrapper.instance(options)
+
+if command == 'clean'
+ if instance.started?
+ $stderr.puts "Please stop solr before cleaning"
+ exit 1
+ end
+ $stderr.puts "cleaning #{instance.instance_dir}..."
+ instance.remove_instance_dir!
+ exit 0
+end
+
$stderr.print "Starting Solr #{instance.version} on port #{instance.port} ... "
instance.wrap do |conn|
conn.with_collection(collection_options) do
$stderr.puts "http://#{instance.host}:#{instance.port}/solr/"
begin