YUKI Hiroshi
null+****@clear*****
Thu Sep 18 15:42:01 JST 2014
YUKI Hiroshi 2014-09-18 15:42:01 +0900 (Thu, 18 Sep 2014) New Revision: 8b5fc6da643108e92046fcf6fa5b41a4c8e8fc14 https://github.com/droonga/droonga-engine/commit/8b5fc6da643108e92046fcf6fa5b41a4c8e8fc14 Message: Show prompt for configuration values Modified files: bin/droonga-engine-configure lib/droonga/command/droonga_engine.rb Modified: bin/droonga-engine-configure (+65 -7) =================================================================== --- bin/droonga-engine-configure 2014-09-18 15:22:34 +0900 (c4ac437) +++ bin/droonga-engine-configure 2014-09-18 15:42:01 +0900 (db7b42f) @@ -107,6 +107,16 @@ def start_service end end +def input(message, default_value=nil) + print "#{message} [#{default_value}]: " + response = gets + if response.empty? + default_value + else + response + end +end + def confirmed?(message) while true print "#{message} (y/N): " @@ -180,16 +190,64 @@ if options[:clear] end if options[:reset] + if configuration.have_given_host? + host = configuration.host + else + host = input("host", configuration.host) + end + + if configuration.have_given_port? + port = configuration.port + else + port = input("port", configuration.port).to_i + end + + if configuration.have_given_tag? + tag = configuration.tag + else + tag = input("tag", configuration.tag) + end + + if installed_as_service? + daemon = true + elsif configuration.have_given_daemon? + daemon = configuration.daemon? + else + daemon = confirmed?("run as a daemon?") + end + + if installed_as_service? + log_file = Droonga::Path.default_log_file + elsif configuration.have_given_log_file? + log_file = configuration.log_file + else + log_file = input("path to the log file", Droonga::Path.default_log_file) + end + + if configuration.have_given_log_level? + log_level = configuration.log_level + else + log_level = input("log level", configuration.log_level) + end + + unless installed_as_service? + if configuration.have_given_pid_file? + pid_file_path = configuration.pid_file_path + else + pid_file_path = input("path to the PID file", Droonga::Path.default_pid_file) + end + end + new_configuration = { - "host" => configuration.host, - "port" => configuration.port, - "tag" => configuration.tag, - "daemon" => installed_as_service?, - "log_file" => path_from_base_dir(Droonga::Path.default_log_file), + "host" => host, + "port" => port, + "tag" => tag, + "daemon" => daemon, + "log_file" => path_from_base_dir(log_file), + "log_level" => log_level, } unless installed_as_service? - pid_file_path = path_from_base_dir(Droonga::Path.default_pid_file) - new_configuration["pid_file"] = pid_file_path + new_configuration["pid_file"] = path_from_base_dir(pid_file_path) end Droonga::SafeFileWriter.write(Droonga::Path.config, YAML.dump(new_configuration)) Modified: lib/droonga/command/droonga_engine.rb (+38 -0) =================================================================== --- lib/droonga/command/droonga_engine.rb 2014-09-18 15:22:34 +0900 (dc8a922) +++ lib/droonga/command/droonga_engine.rb 2014-09-18 15:42:01 +0900 (ba070b8) @@ -120,6 +120,8 @@ module Droonga @port = config["port"] || Address::DEFAULT_PORT @tag = config["tag"] || Address::DEFAULT_TAG + @given_values = {} + @log_file = nil @daemon = false @pid_file_path = nil @@ -143,6 +145,34 @@ module Droonga File.exist?(Path.config) end + def have_given_host? + @given_values.include?(:host) + end + + def have_given_port? + @given_values.include?(:port) + end + + def have_given_tag? + @given_values.include?(:tag) + end + + def have_given_daemon? + @given_values.include?(:daemon) + end + + def have_given_log_file? + @given_values.include?(:log_file) + end + + def have_given_log_level? + @given_values.include?(:log_level) + end + + def have_given_pid_file? + @given_values.include?(:pid_file) + end + def load_config if have_config_file? YAML.load_file(Path.config) @@ -211,16 +241,19 @@ module Droonga "The host name of the Droonga engine", "(#{@host})") do |host| @host = host + @given_values[:host] = host end parser.on("--port=PORT", Integer, "The port number of the Droonga engine", "(#{@port})") do |port| @port = port + @given_values[:port] = port end parser.on("--tag=TAG", "The tag of the Droonga engine", "(#{@tag})") do |tag| @tag = tag + @given_values[:tag] = tag end end @@ -234,10 +267,12 @@ module Droonga "[#{levels_label}]", "(#{log_level})") do |level| self.log_level = level + @given_values[:log_level] = log_level end parser.on("--log-file=FILE", "Output logs to FILE") do |file| self.log_file = file + @given_values[:log_file] = file end end @@ -247,14 +282,17 @@ module Droonga parser.on("--daemon", "Run as a daemon") do @daemon = true + @given_values[:daemon] = true end parser.on("--no-daemon", "Run as a regular process") do @daemon = false + @given_values[:daemon] = false end parser.on("--pid-file=PATH", "Put PID to PATH") do |path| self.pid_file_path = path + @given_values[:pid_file] = path end end -------------- next part -------------- HTML����������������������������...Download