Skip to content

Commit dc16ab5

Browse files
authored
Merge pull request #7268 from rubygems/revert-json-outdated
Revert "Merge pull request #7167 from nevinera/add-json-output-option"
2 parents 1a9df20 + a1efe40 commit dc16ab5

File tree

3 files changed

+18
-79
lines changed

3 files changed

+18
-79
lines changed

bundler/lib/bundler/cli.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ def add(*gems)
379379
method_option "filter-minor", type: :boolean, banner: "Only list minor newer versions"
380380
method_option "filter-patch", type: :boolean, banner: "Only list patch newer versions"
381381
method_option "parseable", aliases: "--porcelain", type: :boolean, banner: "Use minimal formatting for more parseable output"
382-
method_option "json", type: :boolean, banner: "Produce parseable json output"
383382
method_option "only-explicit", type: :boolean, banner: "Only list gems specified in your Gemfile, not their dependencies"
384383
def outdated(*gems)
385384
require_relative "cli/outdated"

bundler/lib/bundler/cli/outdated.rb

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def run
5353
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
5454
end
5555

56-
if options[:parseable] || options[:json]
56+
if options[:parseable]
5757
Bundler.ui.silence(&definition_resolution)
5858
else
5959
definition_resolution.call
6060
end
6161

62-
Bundler.ui.info "" unless options[:json]
62+
Bundler.ui.info ""
6363

6464
# Loop through the current specs
6565
gemfile_specs, dependency_specs = current_specs.partition do |spec|
@@ -98,24 +98,27 @@ def run
9898
end
9999

100100
if outdated_gems.empty?
101-
if options[:json]
102-
print_gems_json([])
103-
elsif !options[:parseable]
101+
unless options[:parseable]
104102
Bundler.ui.info(nothing_outdated_message)
105103
end
106104
else
107-
relevant_outdated_gems = if options_include_groups
108-
by_group(outdated_gems, filter: options[:group])
109-
else
110-
outdated_gems
111-
end
112-
113-
if options[:json]
114-
print_gems_json(relevant_outdated_gems)
105+
if options_include_groups
106+
relevant_outdated_gems = outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems|
107+
contains_group = groups.split(", ").include?(options[:group])
108+
next unless options[:groups] || contains_group
109+
110+
gems
111+
end.compact
112+
113+
if options[:parseable]
114+
print_gems(relevant_outdated_gems)
115+
else
116+
print_gems_table(relevant_outdated_gems)
117+
end
115118
elsif options[:parseable]
116-
print_gems(relevant_outdated_gems)
119+
print_gems(outdated_gems)
117120
else
118-
print_gems_table(relevant_outdated_gems)
121+
print_gems_table(outdated_gems)
119122
end
120123

121124
exit 1
@@ -159,13 +162,6 @@ def retrieve_active_spec(definition, current_spec)
159162
active_specs.last
160163
end
161164

162-
def by_group(gems, filter: nil)
163-
gems.group_by {|g| g[:groups] }.sort.flat_map do |groups_string, grouped_gems|
164-
next if filter && !groups_string.split(", ").include?(filter)
165-
grouped_gems
166-
end.compact
167-
end
168-
169165
def print_gems(gems_list)
170166
gems_list.each do |gem|
171167
print_gem(
@@ -177,21 +173,6 @@ def print_gems(gems_list)
177173
end
178174
end
179175

180-
def print_gems_json(gems_list)
181-
require "json"
182-
data = gems_list.map do |gem|
183-
gem_data_for(
184-
gem[:current_spec],
185-
gem[:active_spec],
186-
gem[:dependency],
187-
gem[:groups]
188-
)
189-
end
190-
191-
data = { outdated_count: gems_list.count, outdated_gems: data }
192-
Bundler.ui.info data.to_json
193-
end
194-
195176
def print_gems_table(gems_list)
196177
data = gems_list.map do |gem|
197178
gem_column_for(
@@ -231,26 +212,6 @@ def print_gem(current_spec, active_spec, dependency, groups)
231212
Bundler.ui.info output_message.rstrip
232213
end
233214

234-
def gem_data_for(current_spec, active_spec, dependency, groups)
235-
{
236-
current_spec: spec_data_for(current_spec),
237-
active_spec: spec_data_for(active_spec),
238-
dependency: dependency&.to_s,
239-
groups: (groups || "").split(", "),
240-
}
241-
end
242-
243-
def spec_data_for(spec)
244-
{
245-
name: spec.name,
246-
version: spec.version.to_s,
247-
platform: spec.platform,
248-
source: spec.source.to_s,
249-
required_ruby_version: spec.required_ruby_version.to_s,
250-
required_rubygems_version: spec.required_rubygems_version.to_s,
251-
}
252-
end
253-
254215
def gem_column_for(current_spec, active_spec, dependency, groups)
255216
current_version = "#{current_spec.version}#{current_spec.git_version}"
256217
spec_version = "#{active_spec.version}#{active_spec.git_version}"

bundler/spec/bundler/cli_spec.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "bundler/cli"
4-
require "json"
54

65
RSpec.describe "bundle executable" do
76
it "returns non-zero exit status when passed unrecognized options" do
@@ -155,26 +154,6 @@ def out_with_macos_man_workaround
155154
end
156155
end
157156

158-
context "with --json" do
159-
let(:flags) { "--json" }
160-
161-
it "prints json output data when there are outdated gems" do
162-
run_command
163-
out_data = JSON.parse(out)
164-
expect(out_data.keys).to contain_exactly("outdated_count", "outdated_gems")
165-
expect(out_data["outdated_count"]).to eq(1)
166-
expect(out_data["outdated_gems"].length).to eq(1)
167-
168-
gem_data = out_data["outdated_gems"].first
169-
expect(gem_data).to include({
170-
"current_spec" => hash_including("name" => "rack", "version" => "0.9.1"),
171-
"active_spec" => hash_including("name" => "rack", "version" => "1.0.0"),
172-
"dependency" => "rack (= 0.9.1)",
173-
"groups" => ["default"],
174-
})
175-
end
176-
end
177-
178157
context "with --parseable" do
179158
let(:flags) { "--parseable" }
180159

0 commit comments

Comments
 (0)