Class: Botbckt::Cmd

Inherits:
Object
  • Object
show all
Defined in:
lib/botbckt/cmd.rb

Overview

:nodoc:

Constant Summary collapse

SEVERITY =
%w{0 1 2 3 4 5}
SEVERITY_ALIASES =
{ "DEBUG" => 0, "INFO" => 1, "WARN" => 2, "ERROR" => 3, "FATAL" => 4, "UNKNOWN" => 5}

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/botbckt/cmd.rb', line 12

def self.parse(args)
  options = {}
  options[:user] = 'botbckt'
  options[:port] = 6667
  options[:channels] = []
  options[:backend_port] = 6379
  
  opts = OptionParser.new do |opts|
    opts.banner = 'Usage: botbckt [options]'
  
    opts.separator ''
    opts.separator 'Options:'
    
    opts.on('-u', '--user [USER]', 'Username to identify as. (default: botbckt)') do |user|
      options[:user] = user
    end
    
    opts.on('-p', '--password [PASSWORD]', 'Password to authenticate with.') do |pass|
      options[:password] = pass
    end
    
    opts.on('-s', '--server SERVER', 'Address of the IRC server.') do |server|
      options[:server] = server
    end
    
    opts.on('-P', '--port [PORT]', Integer, 'Port of the IRC server. (default: 6667)') do |port|
      options[:port] = port
    end
    
    opts.on('-c', '--channels [x,y,z]', Array,
            'Comma-separated list of channels to JOIN. Do not include the # prefix.') do |channels|
      options[:channels] = channels
    end
  
    opts.on('-l', '--logfile [FILE]', 'Log file. (default botbckt.log)') do |log|
      options[:log] = log
    end
  
    severities = SEVERITY_ALIASES.keys.join(', ')
    opts.on('-V', '--verbosity [LEVEL]', SEVERITY, SEVERITY_ALIASES, Integer,
            "Minimum severity level to log.Accepted values are: #{severities}. (default: INFO)") do |level|
      options[:log_level] = level
    end
    
    opts.on('-b', '--backend-host [SERVER]', 'Address of a Redis server.') do |backend|
      options[:backend_host] = backend
    end
    
    opts.on('-B', '--backend-port [PORT]', Integer, 'Port of a Redis server. (default: 6379)') do |port|
      options[:backend_port] = port
    end
    
    opts.on('-D', '--[no-]daemonize', 'Fork and run in the background. (default: true)') do |daemon|
      options[:daemonize] = daemon
    end
    
    opts.on('-i', '--pid FILE', 'File to store PID (default: botbckt.pid)') do |file|
      options[:pid] = file
    end
    
    opts.on_tail('-h', '--help', 'Show this message.') do |help|
      puts opts
      exit
    end
  end
  
  opts.parse!(args)
  options
rescue OptionParser::ParseError
  puts opts
  exit
end

.run(args) ⇒ Object



8
9
10
# File 'lib/botbckt/cmd.rb', line 8

def self.run(args)
  Botbckt::Bot.start parse(args)
end