Class: Mantle::CLI

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

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



9
10
11
# File 'lib/mantle/cli.rb', line 9

def initialize
  @options = {}
end

Instance Method Details

#configure_sidekiqObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mantle/cli.rb', line 48

def configure_sidekiq
  if namespace = Mantle.configuration.redis_namespace
    Mantle.logger.info("Configuring Mantle to listen on Redis namespace: #{namespace}")

    Sidekiq.configure_client do |config|
      config.redis = { url: ENV["REDIS_URL"], namespace: namespace }
    end

    Sidekiq.configure_server do |config|
      config.redis = { url: ENV["REDIS_URL"], namespace: namespace }
    end
  end
end

#listenObject



62
63
64
# File 'lib/mantle/cli.rb', line 62

def listen
  Mantle::MessageBus.new.listen
end

#load_configObject



42
43
44
45
46
# File 'lib/mantle/cli.rb', line 42

def load_config
  require File.expand_path(
    options.fetch :config, './config/initializers/mantle'
  )
end

#parse_options(args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mantle/cli.rb', line 19

def parse_options(args)
  optparser = OptionParser.new do |opts|
    opts.banner = "Usage: mantle <command> [options]"

    opts.on("-c", "--config CONFIG_FILE",
            "Path to configuration file (initializer)") do |arg|
      options[:config] = arg
    end

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

    opts.on_tail("--version", "Show version") do
      puts ::Mantle::VERSION
      exit
    end
  end

  optparser.parse!(args)
end

#setup(args = ARGV) ⇒ Object



13
14
15
16
17
# File 'lib/mantle/cli.rb', line 13

def setup(args = ARGV)
  parse_options(args)
  load_config
  configure_sidekiq
end