This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
cli.rb
71 lines (62 loc) · 1.72 KB
/
cli.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
$:.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 < Thor
def self.banner(task)
task.formatted_usage(self, false)
end
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
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
end
rescue VersionConflict => e
puts e.message
end
desc "install", "Install the current environment to the system"
def install
Installer.install(Bundler.root, Bundler.definition)
end
desc "lock", "Locks a resolve"
def lock
environment = Bundler.load
environment.lock
end
desc "pack", "Packs all the gems to vendor/cache"
def pack
environment = Bundler.load
environment.pack
end
private
def with_rescue
yield
rescue GemfileNotFound => e
puts e.message
exit 1
end
end
end