lib/bundler/patch/cli.rb in bundler-patch-0.7.2 vs lib/bundler/patch/cli.rb in bundler-patch-0.8.0
- old
+ new
@@ -10,10 +10,12 @@
on '-p', '--prefer_minimal', 'Prefer minimal version updates over most recent release (or minor if -m used).'
on '-s', '--strict_updates', 'Restrict any gem to be upgraded past most recent release (or minor if -m used).'
on '-l', '--list', 'List vulnerable gems and new version target. No updates will be performed.'
on '-v', '--vulnerable_gems_only', 'Only update vulnerable gems.'
on '-a=', '--advisory_db_path=', 'Optional custom advisory db path. `gems` dir will be appended to this path.'
+ on '-r', '--ruby', 'Update Ruby version in related files.'
+ on '--rubies=', 'Supported Ruby versions. Comma delimited or multiple switches.', as: Array, delimiter: ','
on '-h', 'Show this help'
on '--help', 'Show README.md'
end
options = opts.to_hash
@@ -43,24 +45,17 @@
def patch(options={})
Bundler.ui = Bundler::UI::Shell.new
return list(options) if options[:list]
- _patch(options)
+ patch_ruby(options[:rubies]) if options[:ruby]
+
+ patch_gems(options)
end
private
- def conservative_update(gem_patches, options={}, bundler_def=nil)
- prep = DefinitionPrep.new(bundler_def, gem_patches, options).tap { |p| p.prep }
-
- # update => true is very important, otherwise without any Gemfile changes, the installer
- # may end up concluding everything can be resolved locally, nothing is changing,
- # and then nothing is done. lib/bundler/cli/update.rb also hard-codes this.
- Bundler::Installer.install(Bundler.root, prep.bundler_def, {'update' => true})
- end
-
def list(options)
gem_patches = AdvisoryConsolidator.new(options).vulnerable_gems
if gem_patches.empty?
Bundler.ui.info @no_vulns_message
@@ -70,11 +65,15 @@
Bundler.ui.info '-------------------------'
Bundler.ui.info gem_patches.map(&:to_s).uniq.sort.join("\n")
end
end
- def _patch(options)
+ def patch_ruby(supported)
+ RubyVersion.new(patched_versions: supported).update
+ end
+
+ def patch_gems(options)
vulnerable_patches = AdvisoryConsolidator.new(options).patch_gemfile_and_get_gem_specs_to_patch
requested_patches = (options.delete(:gems_to_update) || []).map { |gem_name| GemPatch.new(gem_name: gem_name) }
all_gem_patches = GemsToPatchReconciler.new(vulnerable_patches, requested_patches).reconciled_patches
all_gem_patches.push(*vulnerable_patches) if options[:vulnerable_gems_only] && all_gem_patches.empty?
@@ -101,9 +100,18 @@
Bundler.ui.info 'Updating all gems conservatively.'
else
Bundler.ui.info "Updating '#{all_gem_patches.map(&:gem_name).join(' ')}' conservatively."
end
conservative_update(all_gem_patches, options)
+ end
+
+ def conservative_update(gem_patches, options={}, bundler_def=nil)
+ prep = DefinitionPrep.new(bundler_def, gem_patches, options).tap { |p| p.prep }
+
+ # update => true is very important, otherwise without any Gemfile changes, the installer
+ # may end up concluding everything can be resolved locally, nothing is changing,
+ # and then nothing is done. lib/bundler/cli/update.rb also hard-codes this.
+ Bundler::Installer.install(Bundler.root, prep.bundler_def, {'update' => true})
end
end
end
if __FILE__ == $0