Class: RubyMaat::CLI

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

Overview

Command Line Interface - Ruby port of code-maat.cmd-line

Constant Summary collapse

VERSION_INFO =
"Ruby Maat version #{RubyMaat::VERSION} - A Ruby port of Code Maat".freeze

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



15
16
17
18
# File 'lib/ruby_maat/cli.rb', line 15

def initialize
  @options = {}
  @parser = build_option_parser
end

Instance Method Details

#run(args) ⇒ Object



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
# File 'lib/ruby_maat/cli.rb', line 20

def run(args)
  @parser.parse!(args)

  if @options[:help]
    puts usage
    exit 0
  end

  validate_required_options!

  if @options[:generate_log] || @options[:interactive]
    handle_log_generation
  else
    app = App.new(@options)
    app.run
  end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
  warn "Error: #{e.message}"
  warn usage
  exit 1
rescue ArgumentError => e
  warn "Error: #{e.message}"
  warn usage
  exit 1
rescue => e
  warn "Error: #{e.message}"
  warn e.backtrace.join("\n") if @options[:verbose]
  exit 1
end