[rubygems/rubygems] Revert "Merge pull request #7167 from nevinera/add-json-output-option-to-bundle-outdated"
This reverts commit https://github.com/rubygems/rubygems/commit/a4ac5116b8ea, reversing changes made to https://github.com/rubygems/rubygems/commit/8a6b180d0ae5. https://github.com/rubygems/rubygems/commit/a1efe4015d
This commit is contained in:
parent
5a0cbc9344
commit
c1f4bfd41f
@ -379,7 +379,6 @@ module Bundler
|
|||||||
method_option "filter-minor", type: :boolean, banner: "Only list minor newer versions"
|
method_option "filter-minor", type: :boolean, banner: "Only list minor newer versions"
|
||||||
method_option "filter-patch", type: :boolean, banner: "Only list patch newer versions"
|
method_option "filter-patch", type: :boolean, banner: "Only list patch newer versions"
|
||||||
method_option "parseable", aliases: "--porcelain", type: :boolean, banner: "Use minimal formatting for more parseable output"
|
method_option "parseable", aliases: "--porcelain", type: :boolean, banner: "Use minimal formatting for more parseable output"
|
||||||
method_option "json", type: :boolean, banner: "Produce parseable json output"
|
|
||||||
method_option "only-explicit", type: :boolean, banner: "Only list gems specified in your Gemfile, not their dependencies"
|
method_option "only-explicit", type: :boolean, banner: "Only list gems specified in your Gemfile, not their dependencies"
|
||||||
def outdated(*gems)
|
def outdated(*gems)
|
||||||
require_relative "cli/outdated"
|
require_relative "cli/outdated"
|
||||||
|
@ -53,13 +53,13 @@ module Bundler
|
|||||||
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
|
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:parseable] || options[:json]
|
if options[:parseable]
|
||||||
Bundler.ui.silence(&definition_resolution)
|
Bundler.ui.silence(&definition_resolution)
|
||||||
else
|
else
|
||||||
definition_resolution.call
|
definition_resolution.call
|
||||||
end
|
end
|
||||||
|
|
||||||
Bundler.ui.info "" unless options[:json]
|
Bundler.ui.info ""
|
||||||
|
|
||||||
# Loop through the current specs
|
# Loop through the current specs
|
||||||
gemfile_specs, dependency_specs = current_specs.partition do |spec|
|
gemfile_specs, dependency_specs = current_specs.partition do |spec|
|
||||||
@ -98,25 +98,28 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
if outdated_gems.empty?
|
if outdated_gems.empty?
|
||||||
if options[:json]
|
unless options[:parseable]
|
||||||
print_gems_json([])
|
|
||||||
elsif !options[:parseable]
|
|
||||||
Bundler.ui.info(nothing_outdated_message)
|
Bundler.ui.info(nothing_outdated_message)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
relevant_outdated_gems = if options_include_groups
|
if options_include_groups
|
||||||
by_group(outdated_gems, filter: options[:group])
|
relevant_outdated_gems = outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems|
|
||||||
else
|
contains_group = groups.split(", ").include?(options[:group])
|
||||||
outdated_gems
|
next unless options[:groups] || contains_group
|
||||||
end
|
|
||||||
|
|
||||||
if options[:json]
|
gems
|
||||||
print_gems_json(relevant_outdated_gems)
|
end.compact
|
||||||
elsif options[:parseable]
|
|
||||||
|
if options[:parseable]
|
||||||
print_gems(relevant_outdated_gems)
|
print_gems(relevant_outdated_gems)
|
||||||
else
|
else
|
||||||
print_gems_table(relevant_outdated_gems)
|
print_gems_table(relevant_outdated_gems)
|
||||||
end
|
end
|
||||||
|
elsif options[:parseable]
|
||||||
|
print_gems(outdated_gems)
|
||||||
|
else
|
||||||
|
print_gems_table(outdated_gems)
|
||||||
|
end
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
@ -159,13 +162,6 @@ module Bundler
|
|||||||
active_specs.last
|
active_specs.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def by_group(gems, filter: nil)
|
|
||||||
gems.group_by {|g| g[:groups] }.sort.flat_map do |groups_string, grouped_gems|
|
|
||||||
next if filter && !groups_string.split(", ").include?(filter)
|
|
||||||
grouped_gems
|
|
||||||
end.compact
|
|
||||||
end
|
|
||||||
|
|
||||||
def print_gems(gems_list)
|
def print_gems(gems_list)
|
||||||
gems_list.each do |gem|
|
gems_list.each do |gem|
|
||||||
print_gem(
|
print_gem(
|
||||||
@ -177,21 +173,6 @@ module Bundler
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_gems_json(gems_list)
|
|
||||||
require "json"
|
|
||||||
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)
|
def print_gems_table(gems_list)
|
||||||
data = gems_list.map do |gem|
|
data = gems_list.map do |gem|
|
||||||
gem_column_for(
|
gem_column_for(
|
||||||
@ -231,26 +212,6 @@ module Bundler
|
|||||||
Bundler.ui.info output_message.rstrip
|
Bundler.ui.info output_message.rstrip
|
||||||
end
|
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)
|
def gem_column_for(current_spec, active_spec, dependency, groups)
|
||||||
current_version = "#{current_spec.version}#{current_spec.git_version}"
|
current_version = "#{current_spec.version}#{current_spec.git_version}"
|
||||||
spec_version = "#{active_spec.version}#{active_spec.git_version}"
|
spec_version = "#{active_spec.version}#{active_spec.git_version}"
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "bundler/cli"
|
require "bundler/cli"
|
||||||
require "json"
|
|
||||||
|
|
||||||
RSpec.describe "bundle executable" do
|
RSpec.describe "bundle executable" do
|
||||||
it "returns non-zero exit status when passed unrecognized options" do
|
it "returns non-zero exit status when passed unrecognized options" do
|
||||||
@ -155,26 +154,6 @@ RSpec.describe "bundle executable" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with --json" do
|
|
||||||
let(:flags) { "--json" }
|
|
||||||
|
|
||||||
it "prints json output data when there are outdated gems" do
|
|
||||||
run_command
|
|
||||||
out_data = JSON.parse(out)
|
|
||||||
expect(out_data.keys).to contain_exactly("outdated_count", "outdated_gems")
|
|
||||||
expect(out_data["outdated_count"]).to eq(1)
|
|
||||||
expect(out_data["outdated_gems"].length).to eq(1)
|
|
||||||
|
|
||||||
gem_data = out_data["outdated_gems"].first
|
|
||||||
expect(gem_data).to include({
|
|
||||||
"current_spec" => hash_including("name" => "rack", "version" => "0.9.1"),
|
|
||||||
"active_spec" => hash_including("name" => "rack", "version" => "1.0.0"),
|
|
||||||
"dependency" => "rack (= 0.9.1)",
|
|
||||||
"groups" => ["default"],
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with --parseable" do
|
context "with --parseable" do
|
||||||
let(:flags) { "--parseable" }
|
let(:flags) { "--parseable" }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user