#!/usr/bin/env ruby # frozen_string_literal: true # Exit cleanly from an early interrupt Signal.trap('INT') do Bundler.ui.debug("\n#{caller.join("\n")}") if defined?(Bundler) exit 1 end require 'bundle-only/messages' install_only = ARGV.to_a.map(&:to_sym) if install_only.empty? exename = File.basename($PROGRAM_NAME) STDERR.puts "Usage: #{exename} group [group [...]]" exit 2 end ENV['BUNDLE_IGNORE_CONFIG'] = 'true' require 'bundler' Bundler.configure gemfile = Pathname.new(Bundler.default_gemfile).expand_path builder = Bundler::Dsl.new builder.eval_gemfile(gemfile) all_groups = builder.dependencies.map(&:groups).flatten.uniq groups_to_skip = all_groups - install_only Bundler.settings.set_command_option :without, groups_to_skip Bundler.settings.set_command_option :with, install_only definition = builder.to_definition(Bundler.default_lockfile, {}) def definition.lock(*); end # never lock or preserve options definition.validate_ruby! Bundler.ui = Bundler::UI::Shell.new installer = Bundler::Installer.install(Bundler.root, definition, system: true) BundleOnly::Messages::Install.output_installation_complete_message(definition) BundleOnly::Messages::Common.output_without_groups_message(:install) BundleOnly::Messages::Common.output_post_install_messages installer.post_install_messages