summaryrefslogtreecommitdiff
path: root/lib/bundler/cli
diff options
context:
space:
mode:
authorEric Mueller <nevinera@gmail.com>2023-11-15 20:11:12 -0800
committergit <svn-admin@ruby-lang.org>2023-11-23 18:03:17 +0000
commitc424d15cb95f0f5a0db711974f7c76928c9633b1 (patch)
treef2e61a7e6f70219c0d7828df3dc2be43fda237aa /lib/bundler/cli
parenta54c98a29f2086d46c95bc15e77dade7dcd18bba (diff)
[rubygems/rubygems] Add --json bundle-outdated flag to produce json-parseable output
https://github.com/rubygems/rubygems/commit/65efa44bc0
Diffstat (limited to 'lib/bundler/cli')
-rw-r--r--lib/bundler/cli/outdated.rb48
1 files changed, 44 insertions, 4 deletions
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb
index 6c05860854..35954ce491 100644
--- a/lib/bundler/cli/outdated.rb
+++ b/lib/bundler/cli/outdated.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require "json"
+
module Bundler
class CLI::Outdated
attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources, :strict
@@ -53,13 +55,13 @@ module Bundler
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
end
- if options[:parseable]
+ if options[:parseable] || options[:json]
Bundler.ui.silence(&definition_resolution)
else
definition_resolution.call
end
- Bundler.ui.info ""
+ Bundler.ui.info "" unless options[:json]
# Loop through the current specs
gemfile_specs, dependency_specs = current_specs.partition do |spec|
@@ -98,7 +100,9 @@ module Bundler
end
if outdated_gems.empty?
- unless options[:parseable]
+ if options[:json]
+ print_gems_json([])
+ elsif !options[:parseable]
Bundler.ui.info(nothing_outdated_message)
end
else
@@ -108,7 +112,9 @@ module Bundler
outdated_gems
end
- if options[:parseable]
+ if options[:json]
+ print_gems_json(relevant_outdated_gems)
+ elsif options[:parseable]
print_gems(relevant_outdated_gems)
else
print_gems_table(relevant_outdated_gems)
@@ -173,6 +179,20 @@ module Bundler
end
end
+ def print_gems_json(gems_list)
+ data = gems_list.map do |gem|
+ gem_data_for(
+ gem[:current_spec],
+ gem[:active_spec],
+ gem[:dependency],
+ gem[:groups]
+ )
+ end
+
+ data = { :outdated_count => gems_list.count, :outdated_gems => data }
+ Bundler.ui.info data.to_json
+ end
+
def print_gems_table(gems_list)
data = gems_list.map do |gem|
gem_column_for(
@@ -212,6 +232,26 @@ module Bundler
Bundler.ui.info output_message.rstrip
end
+ def gem_data_for(current_spec, active_spec, dependency, groups)
+ {
+ :current_spec => spec_data_for(current_spec),
+ :active_spec => spec_data_for(active_spec),
+ :dependency => dependency&.to_s,
+ :groups => (groups || "").split(", "),
+ }
+ end
+
+ def spec_data_for(spec)
+ {
+ :name => spec.name,
+ :version => spec.version.to_s,
+ :platform => spec.platform,
+ :source => spec.source.to_s,
+ :required_ruby_version => spec.required_ruby_version.to_s,
+ :required_rubygems_version => spec.required_rubygems_version.to_s,
+ }
+ end
+
def gem_column_for(current_spec, active_spec, dependency, groups)
current_version = "#{current_spec.version}#{current_spec.git_version}"
spec_version = "#{active_spec.version}#{active_spec.git_version}"