lib/bundler/cli.rb in bundler-0.8.1 vs lib/bundler/cli.rb in bundler-0.9.0.pre1
- old
+ new
@@ -1,89 +1,85 @@
-require "optparse"
+$:.unshift File.expand_path('../vendor', __FILE__)
+require 'thor'
+require 'bundler'
+require 'rubygems/config_file'
+# Work around a RubyGems bug
+Gem.configuration
+
module Bundler
- class CLI
- def self.run(command, options = {})
- new(options).run(command)
- rescue DefaultManifestNotFound => e
- Bundler.logger.error "Could not find a Gemfile to use"
- exit 3
- rescue InvalidEnvironmentName => e
- Bundler.logger.error "Gemfile error: #{e.message}"
- exit 4
- rescue InvalidRepository => e
- Bundler.logger.error e.message
- exit 5
- rescue VersionConflict => e
- Bundler.logger.error e.message
- exit 6
- rescue GemNotFound => e
- Bundler.logger.error e.message
- exit 7
- rescue InvalidCacheArgument => e
- Bundler.logger.error e.message
- exit 8
- rescue SourceNotCached => e
- Bundler.logger.error e.message
- exit 9
- rescue ManifestFileNotFound => e
- Bundler.logger.error e.message
- exit 10
+ class CLI < Thor
+ def self.banner(task)
+ task.formatted_usage(self, false)
end
- def initialize(options)
- Bundler.mode = options[:cached] ? :local : :readwrite
- @options = options
- @bundle = Bundle.load(@options[:manifest])
+ desc "init", "Generates a Gemfile into the current working directory"
+ 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 bundle
- @bundle.install(@options)
+ def initialize(*)
+ super
+ Bundler.ui = UI::Shell.new(shell)
+ Gem::DefaultUserInteraction.ui = UI::RGProxy.new(Bundler.ui)
end
- def cache
- gemfile = @options[:cache]
-
- if File.extname(gemfile) == ".gem"
- if !File.exist?(gemfile)
- raise InvalidCacheArgument, "'#{gemfile}' does not exist."
+ desc "check", "Checks if the dependencies listed in Gemfile are satisfied by currently installed gems"
+ def check
+ with_rescue do
+ env = Bundler.load
+ # Check top level dependencies
+ missing = env.dependencies.select { |d| env.index.search(d).empty? }
+ if missing.any?
+ puts "The following dependencies are missing"
+ missing.each do |d|
+ puts " * #{d}"
+ end
+ else
+ env.specs
+ puts "The Gemfile's dependencies are satisfied"
end
- @bundle.cache(gemfile)
- elsif File.directory?(gemfile) || gemfile.include?('/')
- if !File.directory?(gemfile)
- raise InvalidCacheArgument, "'#{gemfile}' does not exist."
- end
- gemfiles = Dir["#{gemfile}/*.gem"]
- if gemfiles.empty?
- raise InvalidCacheArgument, "'#{gemfile}' contains no gemfiles"
- end
- @bundle.cache(*gemfiles)
- else
- raise InvalidCacheArgument, "w0t? '#{gemfile}' means nothing to me."
end
+ rescue VersionConflict => e
+ puts e.message
end
- def prune
- Bundler.mode = :local
- @bundle.prune(@options)
- end
+ desc "install", "Install the current environment to the system"
+ method_option :without, :type => :array, :banner => "Exclude gems thar are part of the specified named group"
+ def install
+ opts = options.dup
+ opts[:without] ||= []
+ opts[:without].map! { |g| g.to_sym }
- def list
- @bundle.list(@options)
+ Installer.install(Bundler.root, Bundler.definition, opts)
+ rescue Bundler::GemNotFound => e
+ puts e.message
+ exit 1
end
- def list_outdated
- @bundle.list_outdated(@options)
+ desc "lock", "Locks a resolve"
+ def lock
+ environment = Bundler.load
+ environment.lock
end
- def exec
- @bundle.setup_environment
- # w0t?
- super(*$command)
+ desc "pack", "Packs all the gems to vendor/cache"
+ def pack
+ environment = Bundler.load
+ environment.pack
end
- def run(command)
- send(command)
- end
+ private
+ def with_rescue
+ yield
+ rescue GemfileNotFound => e
+ puts e.message
+ exit 1
+ end
end
-end
+end
\ No newline at end of file