summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2018-07-29 21:08:41 -0700
committerSamuel Giddins <segiddins@segiddins.me>2018-07-29 21:08:41 -0700
commit0d17756dac5fa52e8468473916b4632836252646 (patch)
tree119bca3e89e57b4daeab52118d2b3a60d6014de3
parent42c4609e01c0869f5341f658d2a345a8969fa3e2 (diff)
downloadbundler-segiddins/sys-install-command.tar.gz
Add sys-install commandsegiddins/sys-install-command
-rw-r--r--lib/bundler/cli.rb43
-rw-r--r--lib/bundler/friendly_errors.rb2
-rw-r--r--lib/bundler/installer.rb6
3 files changed, 46 insertions, 5 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index f1ff3f4554..8b670acfdd 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -236,6 +236,47 @@ module Bundler
end
end
+ desc "sys-install GEM [REQ...]", "Installs the given gem to the system"
+ method_option "conservative", :type => :boolean, :desc =>
+ "Only enter the installation process if the dependency is not yet satisfied"
+ method_option "redownload", :type => :boolean, :desc =>
+ "Force downloading every gem"
+ def sys_install(name, *requirements)
+ env = ENV.clone
+ conservative = options[:conservative]
+
+ ENV["BUNDLE_GEMFILE"] = "Gemfile"
+ requirements << ">= 0" if requirements.empty?
+ dependency = Dependency.new(name, requirements)
+ conservative = dependency.requirement.exact? if options[:conservative].nil?
+ sources = SourceList.new
+ sources.global_rubygems_source = Bundler.rubygems.sources
+
+ Bundler.settings.temporary(:'path.system' => true) do
+ definition = Definition.new(
+ nil, # lockfile
+ [dependency],
+ sources,
+ false # unlock
+ )
+ definition.validate_runtime!
+
+ if conservative && installed_spec = sources.default_source.send(:installed_specs).local_search(dependency).first
+ Bundler.ui.debug "Skipping install since #{installed_spec.full_name} is installed at `#{installed_spec.full_gem_path}`"
+ return
+ end
+
+ installer = Bundler::Installer.install(Bundler.root, definition, options.dup.merge(
+ :system => true,
+ :force => options[:redownload],
+ :skip_lock => true
+ ))
+ Common.output_post_install_messages(installer.post_install_messages)
+ end
+ ensure
+ ENV.replace(env)
+ end
+
desc "update [OPTIONS]", "Update the current environment"
long_desc <<-D
Update will install the newest versions of the gems listed in the Gemfile. Use
@@ -724,7 +765,7 @@ module Bundler
cmd = current_command
command_name = cmd.name
return if PARSEABLE_COMMANDS.include?(command_name)
- command = ["bundle", command_name] + args
+ command = ["bundle", command_name.tr("_", "-")] + args.map {|a| a =~ /[^a-z0-9_\.-]/i ? a.inspect : a }
options_to_print = options.dup
options_to_print.delete_if do |k, v|
next unless o = cmd.options[k]
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index ae3299a7c8..c44824b75d 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -122,7 +122,7 @@ module Bundler
def self.with_friendly_errors
yield
- rescue SignalException
+ rescue SignalException, SyntaxError
raise
rescue Exception => e
FriendlyErrors.log_error(e)
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index dd30bd5b64..15a624cbcc 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -77,7 +77,7 @@ module Bundler
if @definition.dependencies.empty?
Bundler.ui.warn "The Gemfile specifies no dependencies"
- lock
+ lock unless options[:skip_lock] || Bundler.frozen_bundle?
return
end
@@ -91,7 +91,7 @@ module Bundler
end
install(options)
- lock unless Bundler.frozen_bundle?
+ lock unless options[:skip_lock] || Bundler.frozen_bundle?
Standalone.new(options[:standalone], @definition).generate if options[:standalone]
end
end
@@ -303,7 +303,7 @@ module Bundler
# returns whether or not a re-resolve was needed
def resolve_if_needed(options)
- if !@definition.unlocking? && !options["force"] && !Bundler.settings[:inline] && Bundler.default_lockfile.file?
+ if !@definition.unlocking? && !options["force"] && !Bundler.settings[:inline] && @definition.lockfile && @definition.lockfile.file?
return false if @definition.nothing_changed? && !@definition.missing_specs?
end