Class: Up::CLI::Options

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



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
# File 'lib/up/cli.rb', line 8

def initialize
  super
  @options = {}
  self.banner = 'Usage: up [options]'
  separator ''
  on('-h', '--help', 'Show this message') do
    puts self
    exit
  end
  on('-p', '--port PORT', String, 'Port number the server will listen to. Default: 3000') do |port|
    options[:port] = port.to_i
  end
  on('-b', '--bind ADDRESS', String, 'Address the server will listen to. Default: localhost') do |host|
    options[:host] = host
  end
  on('-s', '--secure', "Use secure sockets.\nWhen using secure sockets, the -a, -c and -k options must be provided") do
    options[:scheme] = 'https'
  end
  on('-a', '--ca-file FILE', String, 'File with CA certs') do |ca_file|
    options[:ca_file] = ca_file
  end
  on('-c', '--cert-file FILE', String, 'File with the servers certificate') do |cert_file|
    options[:cert_file] = cert_file
  end
  on('-k', '--key-file FILE', String, 'File with the servers certificate') do |key_file|
    options[:key_file] = key_file
  end
  on('-l', '--log-file FILE', String, 'Log file') do |log_file|
    options[:logger] = Logger.new(File.new(log_file, 'a+'))
  end
  on('-P', '--pid-file FILE', String, 'PID file') do |pid_file|
    options[:pid_file] = pid_file
  end
  on('-v', '--version', 'Show version') do
    puts "Up! v#{Up::VERSION}"
    exit
  end
  on('-w', '--workers NUMBER', 'For clusters, the number of workers to run. Default: number of processors') do |workers|
    options[:workers] = workers.to_i
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/up/cli.rb', line 7

def options
  @options
end

Instance Method Details

#parse!Object



50
51
52
53
54
55
56
57
58
# File 'lib/up/cli.rb', line 50

def parse!
  super
  if options[:scheme] == 'https'
    if !options[:ca_file] || !options[:cert_file] || !options[:key_file]
      puts "When using -s or --secure the -a,-c- and -k options must be given too!"
      exit 2
    end
  end
end