Class: Berkshelf::API::SrvCtl

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/api/srv_ctl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SrvCtl

Returns a new instance of SrvCtl.

Parameters:

  • options (Hash) (defaults to: {})

    @see Application.run for the list of valid options



66
67
68
69
# File 'lib/berkshelf/api/srv_ctl.rb', line 66

def initialize(options = {})
  @options               = options
  @options[:eager_build] = true
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



62
63
64
# File 'lib/berkshelf/api/srv_ctl.rb', line 62

def options
  @options
end

Class Method Details

.parse_options(args, filename) ⇒ Hash

Parameters:

  • args (Array)

Returns:

  • (Hash)


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
# File 'lib/berkshelf/api/srv_ctl.rb', line 11

def parse_options(args, filename)
  options = Hash.new

  OptionParser.new("Usage: #{filename} [options]") do |opts|
    opts.on("-h", "--host HOST", String, "set the listening address") do |h|
      options[:host] = h
    end

    opts.on("-p", "--port PORT", Integer, "set the listening port") do |v|
      options[:port] = v
    end

    opts.on("-V", "--verbose", "run with verbose output") do
      options[:log_level] = "INFO"
    end

    opts.on("-d", "--debug", "run with debug output") do
      options[:log_level] = "DEBUG"
    end

    opts.on("-q", "--quiet", "silence output") do
      options[:log_location] = '/dev/null'
    end

    opts.on("-c", "--config FILE", String, "path to a configuration file to use") do |v|
      options[:config_file] = v
    end

    opts.on("-v", "--version", "show version") do |v|
      require 'berkshelf/api/version'
      puts Berkshelf::API::VERSION
      exit
    end

    opts.on_tail("-h", "--help", "show this message") do
      puts opts
      exit
    end
  end.parse!(args)

  options.symbolize_keys
end

.run(args, filename) ⇒ Object

Parameters:

  • args (Array)
  • filename (String)


56
57
58
59
# File 'lib/berkshelf/api/srv_ctl.rb', line 56

def run(args, filename)
  options = parse_options(args, filename)
  new(options).start
end

Instance Method Details

#startObject



71
72
73
74
# File 'lib/berkshelf/api/srv_ctl.rb', line 71

def start
  require 'berkshelf/api'
  Berkshelf::API::Application.run(options)
end