class Bundler::CLI
def self.printable_tasks
def self.printable_tasks tasks = super.dup nodoc = /^bundle (cache)/ tasks.reject!{|t| t.first =~ nodoc } tasks end
def cache
def cache environment = Bundler.load environment.cache rescue GemNotFound => e Bundler.ui.error(e.message) Bundler.ui.info "Run `bundle install` to install missing gems." exit 128 end
def check
def check env = Bundler.load # Check top level dependencies missing = env.dependencies.select { |d| env.index.search(d).empty? } if missing.any? Bundler.ui.error "The following dependencies are missing" missing.each do |d| Bundler.ui.error " * #{d}" end Bundler.ui.error "Try running `bundle install`" exit 1 else not_installed = env.specs.select { |spec| !spec.loaded_from } if not_installed.any? not_installed.each { |s| Bundler.ui.error "#{s.name} (#{s.version}) is cached, but not installed" } Bundler.ui.error "Try running `bundle install`" else Bundler.ui.info "The Gemfile's dependencies are satisfied" end end end
def exec(*)
def exec(*) ARGV.delete('exec') # Set PATH paths = (ENV['PATH'] || "").split(File::PATH_SEPARATOR) paths.unshift "#{Bundler.bundle_path}/bin" ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR) # Set BUNDLE_GEMFILE ENV['BUNDLE_GEMFILE'] = Bundler::SharedHelpers.default_gemfile.to_s # Set RUBYOPT locked_env = Bundler.root.join(".bundle/environment.rb") rubyopt = [ENV["RUBYOPT"]].compact if locked_env.exist? rubyopt.unshift "-r#{locked_env.to_s}" else rubyopt.unshift "-rbundler/setup" rubyopt.unshift "-I#{File.expand_path('../..', __FILE__)}" end ENV["RUBYOPT"] = rubyopt.join(' ') # Run Kernel.exec *ARGV end
def init
def init if File.exist?("Gemfile") puts "Gemfile already exists at #{Dir.pwd}/Gemfile" else puts "Writing new Gemfile to #{Dir.pwd}/Gemfile" FileUtils.cp(File.expand_path('../templates/Gemfile', __FILE__), 'Gemfile') end end
def initialize(*)
def initialize(*) super Bundler.ui = UI::Shell.new(shell) Gem::DefaultUserInteraction.ui = UI::RGProxy.new(Bundler.ui) end
def install(path = nil)
def install(path = nil) opts = options.dup opts[:without] ||= [] opts[:without].map! { |g| g.to_sym } # Can't use Bundler.settings for this because settings needs gemfile.dirname ENV['BUNDLE_GEMFILE'] = opts[:gemfile] if opts[:gemfile] Bundler.settings[:path] = path if path Bundler.settings[:disable_shared_gems] = '1' if options["disable-shared-gems"] Bundler.settings.without = opts[:without] remove_lockfiles if options[:relock] Installer.install(Bundler.root, Bundler.definition, opts) # Ensures that .bundle/environment.rb exists # TODO: Figure out a less hackish way to do this Bundler.load lock if options[:relock] end
def locate_gem(name)
def locate_gem(name) spec = Bundler.load.specs.find{|s| s.name == name } raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec spec.full_gem_path end
def lock
def lock if locked? Bundler.ui.info("The bundle is already locked, relocking.") remove_lockfiles end environment = Bundler.load environment.lock rescue GemNotFound, VersionConflict => e Bundler.ui.error(e.message) Bundler.ui.info "Run `bundle install` to install missing gems" exit 128 end
def locked?
def locked? File.exist?("#{Bundler.root}/Gemfile.lock") || File.exist?("#{Bundler.root}/.bundle/environment.rb") end
def open(name)
def open(name) editor = ENV['EDITOR'] return Bundler.ui.info("To open a bundled gem, set $EDITOR") if editor.nil? || editor.empty? command = "#{editor} #{locate_gem(name)}" Bundler.ui.info "Could not run '#{command}'" unless system(command) end
def package
def package lock cache end
def remove_lockfiles
def remove_lockfiles FileUtils.rm_f "#{Bundler.root}/Gemfile.lock" FileUtils.rm_f "#{Bundler.root}/.bundle/environment.rb" end
def show(gem_name = nil)
def show(gem_name = nil) if gem_name Bundler.ui.info locate_gem(gem_name) else environment = Bundler.load Bundler.ui.info "Gems included by the bundle:" environment.specs.sort_by { |s| s.name }.each do |s| Bundler.ui.info " * #{s.name} (#{s.version})" end end end
def unlock
def unlock if locked? remove_lockfiles Bundler.ui.info("The bundle is now unlocked. The dependencies may be changed.") else Bundler.ui.info("The bundle is not currently locked.") end end
def version
def version Bundler.ui.info "Bundler version #{Bundler::VERSION}" end