Class: GifBot::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/gifbot/cli.rb

Class Method Summary collapse

Class Method Details

.run!Object



43
44
45
46
47
# File 'lib/gifbot/cli.rb', line 43

def run!
  set_options

  GifBot.connect(@options)
end

.set_optionsObject



7
8
9
10
11
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
# File 'lib/gifbot/cli.rb', line 7

def set_options
  @options = {}

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: gifbot [options]\n\nExample: gifbot --server=irc.freenode.net --nick=gifbot --channels=ruby,rails"

    opts.separator ''
    opts.separator 'Options:'

    opts.on('--server [HOST]', 'Set the server to connect to') do |server|
      @options[:server] = server unless server.nil?
    end

    opts.on('--nick [NICK]', 'Set gifbot\'s nickname') do |nick|
      @options[:nick] = nick unless nick.nil?
    end

    opts.on('--channels [CHANNELS]', 'Tell gifbot what channels to connect to (comma seperated, without hash)') do |channels|
      @options[:channels] = channels.split(',').map{ |c| '#' + c } unless channels.nil?
    end

    opts.on( '-h', '--help', 'Display this help' ) do
      puts opts
      exit
    end

  end
  
  opts.parse!
          
  unless %w[server nick channels].all? { |k| @options.has_key?(k.to_sym) }
    puts opts
    exit
  end
end