Module: Kajiki

Defined in:
lib/kajiki.rb,
lib/kajiki/runner.rb,
lib/kajiki/handler.rb,
lib/kajiki/presets.rb

Defined Under Namespace

Modules: Handler Classes: Runner

Constant Summary collapse

SUB_COMMANDS =

Available commands.

%w(start stop)
OPT_DESCS =

Description strings for help display.

{
  banner: "Usage: #{File.basename($0)} [options] {#{SUB_COMMANDS.join('|')}}",
  address: 'Bind to address',
  config: 'Load config from file',
  daemonize: 'Run in the background',
  error: 'Output error to file',
  group: 'Group to run as',
  log: 'Log output to file',
  pid: 'Store PID to file',
  port: 'Use port',
  user: 'User to run as'
}

Class Method Summary collapse

Class Method Details

.preset_options(preset, options = {}) ⇒ Object

Preset options for command-line parsing.

Parameters:

  • presets (Symbol)

    are: `:minimal`, `:simple`, or `:server`.


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
# File 'lib/kajiki/presets.rb', line 22

def self.preset_options(preset, options = {})
  case preset
  when :minimal
    Trollop.options do
      banner OPT_DESCS[:banner]
      opt :daemonize, OPT_DESCS[:daemonize]
      opt :pid, OPT_DESCS[:pid], type: :string
    end
  when :simple
    Trollop.options do
      banner OPT_DESCS[:banner]
      opt :config, OPT_DESCS[:config], type: :string if options[:config]
      opt :daemonize, OPT_DESCS[:daemonize]
      opt :error, OPT_DESCS[:error], type: :string unless options[:error] == false
      opt :group, OPT_DESCS[:group], type: :string unless options[:user] == false
      opt :log, OPT_DESCS[:log], type: :string
      opt :pid, OPT_DESCS[:pid], type: :string
      opt :user, OPT_DESCS[:user], type: :string unless options[:user] == false
      depends(:user, :group) unless options[:user] == false
    end
  when :server
    Trollop.options do
      banner OPT_DESCS[:banner]
      opt :address, OPT_DESCS[:address], default: '0.0.0.0'
      opt :config, OPT_DESCS[:config], type: :string if options[:config]
      opt :daemonize, OPT_DESCS[:daemonize]
      opt :error, OPT_DESCS[:error], type: :string unless options[:error] == false
      opt :group, OPT_DESCS[:group], type: :string unless options[:user] == false
      opt :log, OPT_DESCS[:log], type: :string
      opt :pid, OPT_DESCS[:pid], short: 'P', type: :string
      opt :port, OPT_DESCS[:port], default: 4567
      opt :user, OPT_DESCS[:user], type: :string unless options[:user] == false
      depends(:user, :group) unless options[:user] == false
    end
  else
    fail 'Invalid preset option.'
  end
end

.run(opts, &block) ⇒ Object


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

def self.run(opts, &block)
  Runner.run(opts, &block)
end