Class: Mascut::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/mascut/option.rb

Class Method Summary collapse

Class Method Details

.parse(args = ARGV.dup) ⇒ Object



5
6
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
42
43
44
45
46
47
48
49
50
# File 'lib/mascut/option.rb', line 5

def self.parse(args = ARGV.dup)
  {
    :server => 'mongrel',
    :Host   => '0.0.0.0',
    :Port   => 9203
  }.tap do |options|
    OptionParser.new do |opts|
      opts.banner = "Usage: mascut [files] [rack options] [mascut options]"
      
      opts.separator 'Rack options:' # almost same as rack
      opts.on('-s', '--server SERVER', 'serve using SERVER (default: mongrel)') do |s|
        options[:server] = s
      end
      
      opts.on('-o', '--host HOST', 'listen on HOST (default: 0.0.0.0)') do |host|
        options[:Host] = host
      end
      
      opts.on('-p', '--port PORT', 'use PORT (default: 9203)') do |port|
        options[:Port] = port
      end
      
      opts.on('-D', '--daemonize', 'run daemonized in the background') do |d|
        options[:daemonize] = d ? true : false
      end
      
      opts.separator ''
      opts.separator 'Mascut options:'

      opts.on('-m', '--mascut PATH', 'absolute path for comet(default on Mascut::Mascut: /mascut)') do |path|
        options[:mascut] = path.index('/') == 0 ? path : "/#{path}"
      end

      opts.on('-i', '--interval SEC', Float, 'interval to monitor files(default on Mascut::Mascut: 1.0 sec)') do |sec|
        options[:interval] = sec
      end

      opts.on('-j', '--jquery JQUERY', 'jquery file to use for commet') do |file|
        options[:jquery] = file
      end
      
      opts.permute!(args)
      options[:files] = args.size > 0 ? args : nil
    end
  end
end