Class: MemoryProfiler::CLI

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

Instance Method Summary collapse

Instance Method Details

#run(argv) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/memory_profiler/cli.rb', line 31

def run(argv)
  options = {}
  parser = option_parser(options)
  parser.parse!(argv)

  options = DEFAULTS.merge(options)

  # Make sure the user specified at least one file
  unless (script = argv.shift)
    puts parser
    puts ""
    puts "#{VERSION_INFO}  |  ERROR: Must specify a script to run"
    return STATUS_ERROR
  end

  MemoryProfiler.start(reporter_options(options))
  load script

  STATUS_SUCCESS
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::MissingArgument => e
  puts parser
  puts e.message
  STATUS_ERROR
ensure
  report = MemoryProfiler.stop
  report&.pretty_print(**results_options(options))
end