Permalink
Browse files

impl Atig::Client

  • Loading branch information...
1 parent e73f25a commit 03f9268ea498601f760c20809b93f5936647ab9b @hsbt hsbt committed Jan 24, 2012
Showing with 84 additions and 2 deletions.
  1. +1 −2 bin/atig
  2. +1 −0 lib/atig.rb
  3. +22 −0 lib/atig/client.rb
  4. +60 −0 lib/atig/optparse.rb
View
@@ -11,5 +11,4 @@ self_file =
$:.unshift(File.dirname(self_file) + "/../lib")
require 'atig'
-opts = Atig::OptParser.parse!(ARGV)
-Net::IRC::Server.new(opts[:host], opts[:port], Atig::Gateway::Session, opts).start
+Atig::Client.run
View
@@ -10,6 +10,7 @@
require 'atig/version'
require 'atig/monkey'
require 'atig/optparse'
+require 'atig/client'
require 'atig/twitter'
require 'atig/scheduler'
require 'atig/agent'
View
@@ -0,0 +1,22 @@
+require 'logger'
+
+module Atig
+ module Client
+ class << self
+ def run
+ opts = Atig::OptParser.parse!(ARGV)
+
+ opts[:logger] = Logger.new(opts[:log], "weekly")
+ opts[:logger].level = opts[:debug] ? Logger::DEBUG : Logger::INFO
+
+ conf = File.expand_path opts[:conf]
+ if File.exist? conf then
+ opts[:logger].info "Loading #{conf}"
+ load conf
+ end
+
+ Net::IRC::Server.new(opts[:host], opts[:port], Atig::Gateway::Session, opts).start
+ end
+ end
+ end
+end
View
@@ -0,0 +1,60 @@
+require "optparse"
+
+module Atig
+ module OptParser
+ class << self
+ def parse!(argv)
+ opts = {
+ :port => 16668,
+ :host => "localhost",
+ :log => nil,
+ :debug => false,
+ :foreground => false,
+ :conf => '~/.atig/config',
+ }
+
+ OptionParser.new do |parser|
+ parser.instance_eval do
+ self.banner = <<EOB.gsub(/^\t+/, "")
+usage: #{$0} [opts]
+EOB
+ separator ""
+
+ separator "Options:"
+ on("-p", "--port [PORT=#{opts[:port]}]", "port number to listen") do |port|
+ opts[:port] = port
+ end
+
+ on("-h", "--host [HOST=#{opts[:host]}]", "host name or IP address to listen") do |host|
+ opts[:host] = host
+ end
+
+ on("-l", "--log LOG", "log file") do |log|
+ opts[:log] = log
+ end
+
+ on("--debug", "Enable debug mode") do |debug|
+ opts[:log] ||= $stderr
+ opts[:debug] = true
+ end
+
+ on("--memprof", "Enable memory profiler") do|_|
+ require 'memory_profiler'
+ require 'fileutils'
+ FileUtils.mkdir_p "log"
+ MemoryProfiler.start(:string_debug => true)
+ end
+
+ on("-c","--conf [file=#{opts[:conf]}]", "atig configuration file; default is '~/.atig/config'") do|name|
+ opts[:conf] = name
+ end
+
+ parse!(argv)
+ end
+ end
+
+ opts
+ end
+ end
+ end
+end

0 comments on commit 03f9268

Please sign in to comment.