bin/rurema in myrurema-0.0.0 vs bin/rurema in myrurema-0.0.1

- old
+ new

@@ -4,14 +4,15 @@ class Pathname; alias / +; end class Options def initialize(argv) + @command = nil + @open_browser = false @dry_run = false @ruremadir = Pathname("~/.rurema").expand_path @rubyver = RUBY_VERSION - @command = nil @query = "" @optionparser = OptionParser.new{|o| o.on("--init", "initialize rurema"){ @@ -19,11 +20,19 @@ } o.on("--update", "update documents and database"){ @command = :update } + o.on("--server", + "start web server"){ + @command = :server + } + o.on("--browser", + "open web browser (only meaningful with --server)"){ + @open_browser = true + } o.on("--dry-run", "show commands only"){ @dry_run = true } o.on("--ruremadir=PATH", @@ -40,11 +49,11 @@ exit } } @query = @optionparser.parse(argv).join(" ") end - attr_reader :dry_run, :ruremadir, :rubyver + attr_reader :dry_run, :ruremadir, :rubyver, :open_browser attr_reader :command, :query def usage puts @optionparser end @@ -88,15 +97,26 @@ exit end end sh "#{bitclust_path/'bin/refe.rb'}" + - " #{query} -d #{db_path(ver)}", :silent => true + " #{query} -d #{db_path(ver)}", :silent => true end def server - # TODO + th = Thread.new{ + sh "#{bitclust_path/'standalone.rb'}" + + " --baseurl=http://localhost:9292" + + " --port=9292" + + " --database=#{db_path(@opt.rubyver)}" + + " --debug" + } + if @opt.open_browser + cmd = (/mswin/ =~ RUBY_PLATFORM) ? "start" : "open" + sh "#{cmd} http://localhost:9292/view/" + end + th.join end private def init_db(ver) @@ -125,10 +145,9 @@ def has_db?(ver) db_path(ver).directory? end def db_path(ver) - raise ArgumentError, "malformed ver: #{ver}" unless ver =~ /\A\d.\d.\d\z/ @opt.ruremadir / "db" / ver end def sh(cmd, opt={}) puts cmd unless opt[:silent]