9 % rbot [options] [config directory]
14 display a help message and exit
16 display version information and exit
19 [-l, --loglevel _level_]
20 sets the minimum log level verbosity
22 background (daemonize) the bot
23 [-p, --pidfile _filename_]
24 write the bot pid to _filename_
26 The default config directory is <tt>~/.rbot</tt>.
28 The default pidfile is <tt><i>botdir</i>/rbot.pid</tt>.
30 The logfile is located at <tt><i>botdir</i>/<i>botname</i>.log</tt>, and
31 the default loglevel is 1 (INFO messages). Possible values for the loglevel
32 are 0 (DEBUG), 1 (INFO), 2 (WARN), 3 (ERROR), 4 (FATAL).
34 Please note that the logfile doesn't contain IRC logs (which are located at
35 <tt><i>botdir</i>/logs/*</tt>, but only rbot diagnostic messages.
39 # Copyright (C) 2002-2006 Tom Gilbert.
40 # Copyright (C) 2007-2008 Giuseppe Bilotta and the rbot development team
42 # This is free software, see COPYING for licensing details
54 if defined?(SCM_DIR) and File.exists?(File.join(SCM_DIR, '.git'))
56 git_out = `git status`
57 git_out.match(/^# On branch (.*)\n/)
59 branch = $1.dup || "unknown"
60 changed = git_out.match(/^# Change(.*)\n/)
62 git_out = `git log -1 --pretty=format:"%h%n%b%n%ct"`.split("\n")
64 $version_timestamp = git_out.last.to_i
65 if git_out[1].match(/^git-svn-id: \S+@(\d+)/)
68 rev << ", local changes" if changed
70 git_out = `git branch`
71 git_out.match(/^\* (.*)\n/)
72 branch = $1.dup rescue "unknown"
73 rev = "revision " + `git rev-parse HEAD`[0,6]
77 branch = "unknown branch"
78 rev = "unknown revision"
81 $version << " (#{branch} branch, #{rev})"
83 up = File.dirname(__FILE__) + "/.."
84 rev = " (unknown revision)"
86 svn_out = `svn info #{up}`
87 if svn_out =~ /Last Changed Rev: (\d+)/
88 rev = " (revision #{$1}"
90 svn_st = `svn st #{up}`
91 if svn_st =~ /^[MDA] /
92 rev << ", local changes"
104 opts = GetoptLong.new(
105 ["--background", "-b", GetoptLong::NO_ARGUMENT],
106 ["--debug", "-d", GetoptLong::NO_ARGUMENT],
107 ["--help", "-h", GetoptLong::NO_ARGUMENT],
108 ["--loglevel", "-l", GetoptLong::REQUIRED_ARGUMENT],
109 ["--trace", "-t", GetoptLong::REQUIRED_ARGUMENT],
110 ["--pidfile", "-p", GetoptLong::REQUIRED_ARGUMENT],
111 ["--version", "-v", GetoptLong::NO_ARGUMENT]
117 opts.each {|opt, arg|
118 $debug = true if(opt == "--debug")
119 $daemonize = true if(opt == "--background")
120 $opts[opt.sub(/^-+/, "")] = arg
123 $cl_loglevel = $opts["loglevel"].to_i if $opts["loglevel"]
126 set_trace_func proc { |event, file, line, id, binding, classname|
127 if classname.to_s == $opts["trace"]
128 printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
133 defaultlib = File.expand_path(File.dirname($0) + '/../lib')
135 if File.directory? "#{defaultlib}/rbot"
136 unless $:.include? defaultlib
137 $:.unshift defaultlib
142 require 'rbot/ircbot'
143 rescue LoadError => e
144 puts "Error: couldn't find the rbot/ircbot module (or one of its dependencies)\n"
149 if ($opts["version"])
150 puts "rbot #{$version}"
155 puts "usage: rbot [options] [config directory]"
156 puts " -h, --help this message"
157 puts " -v, --version version information"
158 puts " -d, --debug enable debug messages"
159 puts " -l, --loglevel sets the log level verbosity"
160 puts " -b, --background background (daemonize) the bot"
161 puts " -p, --pidfile write the bot pid to file"
162 puts "config directory defaults to ~/.rbot"
166 if(bot = Irc::Bot.new(ARGV.shift, :argv => orig_opts))