#!/usr/bin/env ruby # frozen_string_literal: true # in case we execute via ./bin add_load_path = -> do local_lib = File.expand_path('../lib', __dir__) $LOAD_PATH << local_lib unless $LOAD_PATH.include? local_lib end add_load_path.call require 'optparse' require 'bumbler' options = {} OptionParser.new do |parser| parser.banner = <<~BANNER Bumbler shows how long loading your bundle components take. Usage: bumbler Options: BANNER parser.on("-t", "--threshold MILLISECONDS", Integer, "Threshold in ms to be listed as slow") { |t| options[:threshold] = t } parser.on("--initializers", "Show load time of initializers") { options[:initializers] = true } parser.on("--all", "Show all load times") { options[:all] = true } parser.on("-h", "--help", "Show this.") { puts parser; exit } parser.on('-v', '--version', 'Show Version') { puts Bumbler::VERSION; exit } end.parse! abort "Not arguments supported" unless ARGV.empty? Bumbler::Hooks.slow_threshold = options[:threshold] if options[:threshold] if options[:initializers] require './config/application' add_load_path.call # bundler kicks us out require 'bumbler/track_initializers' require './config/environment' elsif File.exist?('./config/environment') require 'bumbler/go' require './config/environment' add_load_path.call # bundler kicks us out else require 'bumbler/go' Bundler.require(*Bundler.definition.groups) end Bumbler::Stats.print_overview if options[:all] Bumbler::Stats.print_tracked_items else Bumbler::Stats.print_slow_items end