Module: RailsLogConverter::CLI::Options

Included in:
RailsLogConverter::CLI
Defined in:
lib/rails_log_converter/cli/options.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

The hash of (parsed) command-line options



19
20
21
# File 'lib/rails_log_converter/cli/options.rb', line 19

def options
  @options
end

Class Method Details

.included(receiver) ⇒ Object



13
14
15
# File 'lib/rails_log_converter/cli/options.rb', line 13

def self.included(receiver)
  receiver.extend(ClassMethods)
end

Instance Method Details

#option_parserObject



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

def option_parser
  @option_parser ||= OptionParser.new do |opts|
    script_name = File.basename($0)
    opts.banner = "USAGE: #{script_name} log_file.log"
    
    opts.on('-d', '--debug', 'Run application in debug mode') { |value| Configuration.debug = true }
              
    opts.on("-h", "--help", "Show this message") do
      UI.puts opts
      exit
    end

    # Another typical switch to print the version.
    opts.on("-v","--version", "Show version") do
      UI.puts "#{script_name} version: #{RailsLogConverter::Version::STRING}"
      exit
    end
  end
end

#parse_options!Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rails_log_converter/cli/options.rb', line 42

def parse_options!
  
  option_parser.parse!(args)
  
  unless(args[0])
    warn "Log file not given"
    warn option_parser
    exit
  end
          
  self.file_path = File.expand_path(args[0])

  if !File.exists?(self.file_path)
    warn "#{self.file_path}' does not exist."
    exit
  elsif !File.file?(self.file_path)
    warn "#{self.file_path}' is not a file."
    exit
  elsif args.length > 2
    warn "Too many arguments;"
    warn option_parser
    exit
  end
end