lib/jschat/client.rb in jschat-0.1.1 vs lib/jschat/client.rb in jschat-0.1.2
- old
+ new
@@ -4,24 +4,37 @@
require 'ncurses'
require 'optparse'
require 'time'
options = {}
-
+default_config_file = '~/.jschat/config.json'
ARGV.clone.options do |opts|
script_name = File.basename($0)
opts.banner = "Usage: #{$0} [options]"
opts.separator ""
+ opts.on("-c", "--config=PATH", String, "Configuration file location (#{default_config_file})") { |o| options['config'] = o }
opts.on("-h", "--hostname=host", String, "JsChat server hostname") { |o| options['hostname'] = o }
opts.on("-p", "--port=port", String, "JsChat server port number") { |o| options['port'] = o }
opts.on("-r", "--room=#room", String, "Channel to auto-join: remember to escape the hash") { |o| options['room'] = o }
opts.on("-n", "--nick=name", String, "Your name") { |o| options['nick'] = o }
opts.on("--help", "-H", "This text") { puts opts; exit 0 }
opts.parse!
end
+
+# Command line options will overrides these
+def load_options(path)
+ path = File.expand_path path
+ if File.exists? path
+ JSON.parse(File.read path)
+ else
+ {}
+ end
+end
+
+options = load_options(options['config'] || default_config_file).merge options
ClientConfig = {
:port => options['port'] || '6789',
:ip => options['hostname'] || '0.0.0.0',
:name => options['nick'] || ENV['LOGNAME'],