Class: Clarity::CLI

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

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ 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
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
84
85
86
87
88
89
90
91
92
# File 'lib/clarity/cli.rb', line 5

def self.execute(stdout, arguments=[])
  
  options = {
    :username => nil,
    :password => nil,
    :log_files => nil,
    :port => 8080,
    :address => "0.0.0.0",
    :user => nil,
    :group => nil,
    :relative_root => nil
  }
  
  mandatory_options = %w(  )
  
  ARGV.options do |opts|
    opts.banner = "Usage:  #{File.basename($PROGRAM_NAME)} [options] directory"

    opts.separator " "
    opts.separator "Specific options:"

    opts.on( "-f", "--config=FILE", String, "Config file (yml)" ) do |opt|
      config = YAML.load_file( opt )
      config.keys.each do |key|
        options[key.to_sym] = config[key]
      end
    end

    opts.on( "-p", "--port=PORT", Integer, "Port to listen on" ) do |opt|
      options[:port] = opt
    end  

    opts.on( "-b", "--address=ADDRESS", String, "Address to bind to (default 0.0.0.0)" ) do |opt|
      options[:address] = opt
    end  

    opts.on( "-r", "--relative=ROOT", String, "Run under a relative root" ) do |opt|
      options[:relative_root] = opt
    end

    opts.on( "--include=MASK", String, "File mask of logs to add (default: **/*.log*)" ) do |opt|
      options[:log_files] ||= []
      options[:log_files] += opt
    end
    
    opts.on( "--user=USER", String, "User to run as" ) do |opt|
      options[:user] = opt
    end
    
    opts.separator " "
    opts.separator "Password protection:"

    opts.on( "--username=USER", String, "Enable httpauth username" ) do |opt|
      options[:username] = opt
    end

    opts.on( "--password=PASS", String, "Enable httpauth password" ) do |opt|
      options[:password] = opt
    end

    opts.separator " "
    opts.separator "Misc:"

    opts.on( "-h", "--help", "Show this message." ) do
      puts opts
      exit
    end

    opts.separator " "

    begin
      opts.parse!(arguments)
   
      options[:log_files] ||= ['**/*.log*']
      
      if arguments.first
        Dir.chdir(arguments.first)
        
        ::Clarity::Server.run(options)
        
      else
        puts opts
        exit(1)
      end
    end
  end
        
end