Class: LolDba::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ CLI

Returns a new instance of CLI.



27
28
29
30
# File 'lib/lol_dba/cli.rb', line 27

def initialize(path, options)
  @path = path
  @options = options
end

Class Method Details

.parse_optionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lol_dba/cli.rb', line 11

def parse_options
  options = {}
  OptionParser.new do |opts|
    opts.on('-d', '--debug',
            'Show stack traces when an error occurs.') do |opt|
      options[:debug] = opt
    end
    opts.on_tail('-v', '--version', 'Show version') do
      puts LolDba::VERSION
      exit
    end
  end.parse!
  options
end

.startObject



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

def start
  new(Dir.pwd, parse_options).start(ARGV.first)
end

Instance Method Details

#start(arg) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lol_dba/cli.rb', line 32

def start(arg)
  load_application
  select_action(arg)
rescue SystemExit
  raise $!
rescue Exception => exception
  if @options[:debug]
    warn "Failed: #{exception.class}: #{exception.message}"
    warn exception.backtrace.map { |trace| "    from #{trace}" }
  end
end