Module: Codebot::Options

Defined in:
lib/codebot/options.rb,
lib/codebot/options/base.rb,
lib/codebot/options/core.rb,
lib/codebot/options/network.rb,
lib/codebot/options/integration.rb

Overview

This module provides functionality for parsing command-line options.

Defined Under Namespace

Classes: Base, Core, Integration, Network

Class Method Summary collapse

Class Method Details

.with_core(opts, rehash = false) {|Core| ... } ⇒ Object

Creates a new Core from the specified command-line options. Errors of type UserError are handled if they occur in the given block.

Parameters:

  • opts (Hash)

    the options to initialize the core with

  • rehash (Boolean) (defaults to: false)

    whether to ask a running instance to rehash its configuration after invoking the block

Yields:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/codebot/options.rb', line 17

def self.with_core(opts, rehash = false)
  core = ::Codebot::Core.new(
    config_file: opts[:config],
    ipc_pipe: opts[:pipe]
  )
  with_errors { yield core }
  return unless rehash

  with_ipc_client(opts) do |ipc|
    break unless ipc.send_rehash(!opts[:pipe].nil?)

    puts 'Rehashing the running instance...' unless opts[:quiet]
  end
end

.with_errorsObject

Invokes the given block, handling UserError errors.



33
34
35
36
37
38
# File 'lib/codebot/options.rb', line 33

def self.with_errors
  yield
rescue UserError => e
  STDERR.puts "Error: #{e.message}"
  exit 1
end

.with_ipc_client(opts) {|IPCClient| ... } ⇒ Object

Creates a new IPCClient from the specified command-line options. Errors of type UserError are handled if they occur in the given block.

Parameters:

  • opts (Hash)

    the options to initialize the client with

Yields:



45
46
47
# File 'lib/codebot/options.rb', line 45

def self.with_ipc_client(opts)
  with_errors { yield IPCClient.new(opts[:pipe]) }
end