mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Use JSON.pretty_generate
It's dramatically more human readable for very little difference in space.
This commit is contained in:
parent
79940b2a27
commit
6f071a06f8
@ -39,7 +39,7 @@ module Cask
|
|||||||
sig { void }
|
sig { void }
|
||||||
def run
|
def run
|
||||||
if args.json == "v1"
|
if args.json == "v1"
|
||||||
puts JSON.generate(args.named.to_casks.map(&:to_h))
|
puts JSON.pretty_generate(args.named.to_casks.map(&:to_h))
|
||||||
elsif args.github?
|
elsif args.github?
|
||||||
raise CaskUnspecifiedError if args.no_named?
|
raise CaskUnspecifiedError if args.no_named?
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
if json
|
if json
|
||||||
puts JSON.generate(output.map(&:to_h))
|
puts JSON.pretty_generate(output.map(&:to_h))
|
||||||
elsif one
|
elsif one
|
||||||
puts output.map(&:to_s)
|
puts output.map(&:to_s)
|
||||||
elsif full_name
|
elsif full_name
|
||||||
|
@ -202,7 +202,7 @@ module Homebrew
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
puts JSON.generate(json)
|
puts JSON.pretty_generate(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_remote_path(remote, path)
|
def github_remote_path(remote, path)
|
||||||
|
@ -64,7 +64,7 @@ module Homebrew
|
|||||||
"formulae" => json_info(formulae, args: args),
|
"formulae" => json_info(formulae, args: args),
|
||||||
"casks" => json_info(casks, args: args),
|
"casks" => json_info(casks, args: args),
|
||||||
}
|
}
|
||||||
puts JSON.generate(json)
|
puts JSON.pretty_generate(json)
|
||||||
|
|
||||||
outdated = formulae + casks
|
outdated = formulae + casks
|
||||||
|
|
||||||
|
@ -88,6 +88,6 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_tap_json(taps)
|
def print_tap_json(taps)
|
||||||
puts JSON.generate(taps.map(&:to_hash))
|
puts JSON.pretty_generate(taps.map(&:to_hash))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -78,7 +78,7 @@ module Homebrew
|
|||||||
|
|
||||||
state[key] = new_state
|
state[key] = new_state
|
||||||
|
|
||||||
state_file.atomic_write JSON.generate(state) unless args.dry_run?
|
state_file.atomic_write JSON.pretty_generate(state) unless args.dry_run?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts JSON.generate(formulae_checked.compact)
|
puts JSON.pretty_generate(formulae_checked.compact)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(formula_or_cask: T.any(Formula, Cask::Cask), full_name: T::Boolean).returns(String) }
|
sig { params(formula_or_cask: T.any(Formula, Cask::Cask), full_name: T::Boolean).returns(String) }
|
||||||
|
@ -306,13 +306,7 @@ class Bottle
|
|||||||
|
|
||||||
filename = Filename.create(formula, tag, spec.rebuild).bintray
|
filename = Filename.create(formula, tag, spec.rebuild).bintray
|
||||||
|
|
||||||
# TODO: this will need adjusted when if we use GitHub Packages by default
|
path, resolved_basename = spec.path_resolved_basename(@name, checksum, filename)
|
||||||
path, resolved_basename = if spec.root_url.match?(GitHubPackages::URL_REGEX)
|
|
||||||
image_name = GitHubPackages.image_formula_name(@name)
|
|
||||||
["#{image_name}/blobs/sha256:#{checksum}", filename]
|
|
||||||
else
|
|
||||||
filename
|
|
||||||
end
|
|
||||||
|
|
||||||
@resource.url("#{spec.root_url}/#{path}", select_download_strategy(spec.root_url_specs))
|
@resource.url("#{spec.root_url}/#{path}", select_download_strategy(spec.root_url_specs))
|
||||||
@resource.downloader.resolved_basename = resolved_basename if resolved_basename.present?
|
@resource.downloader.resolved_basename = resolved_basename if resolved_basename.present?
|
||||||
@ -424,7 +418,7 @@ class BottleSpecification
|
|||||||
|
|
||||||
attr_rw :rebuild
|
attr_rw :rebuild
|
||||||
attr_accessor :tap
|
attr_accessor :tap
|
||||||
attr_reader :all_tags_cellar, :checksum, :collector, :root_url_specs, :repository, :prefix
|
attr_reader :all_tags_cellar, :collector, :root_url_specs, :repository, :prefix
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def initialize
|
def initialize
|
||||||
@ -452,6 +446,16 @@ class BottleSpecification
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def path_resolved_basename(name, checksum, filename)
|
||||||
|
if root_url.match?(GitHubPackages::URL_REGEX)
|
||||||
|
image_name = GitHubPackages.image_formula_name(name)
|
||||||
|
["#{image_name}/blobs/sha256:#{checksum}", filename]
|
||||||
|
else
|
||||||
|
# TODO: this can be removed when we no longer use Bintray
|
||||||
|
filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def cellar(val = nil)
|
def cellar(val = nil)
|
||||||
if val.present?
|
if val.present?
|
||||||
odeprecated(
|
odeprecated(
|
||||||
|
@ -87,7 +87,89 @@ describe Cask::Cmd::List, :cask do
|
|||||||
let(:casks) { ["local-caffeine", "local-transmission", "third-party/tap/third-party-cask"] }
|
let(:casks) { ["local-caffeine", "local-transmission", "third-party/tap/third-party-cask"] }
|
||||||
let(:expected_output) {
|
let(:expected_output) {
|
||||||
<<~EOS
|
<<~EOS
|
||||||
[{"token":"local-caffeine","full_token":"local-caffeine","tap":"homebrew/cask","name":[],"desc":null,"homepage":"https://brew.sh/","url":"file:///usr/local/Homebrew/Library/Homebrew/test/support/fixtures/cask/caffeine.zip","appcast":null,"version":"1.2.3","installed":"1.2.3","outdated":false,"sha256":"67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94","artifacts":[["Caffeine.app"]],"caveats":null,"depends_on":{},"conflicts_with":null,"container":null,"auto_updates":null},{"token":"local-transmission","full_token":"local-transmission","tap":"homebrew/cask","name":["Transmission"],"desc":"BitTorrent client","homepage":"https://transmissionbt.com/","url":"file:///usr/local/Homebrew/Library/Homebrew/test/support/fixtures/cask/transmission-2.61.dmg","appcast":null,"version":"2.61","installed":"2.61","outdated":false,"sha256":"e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68","artifacts":[["Transmission.app"]],"caveats":null,"depends_on":{},"conflicts_with":null,"container":null,"auto_updates":null},{"token":"third-party-cask","full_token":"third-party/tap/third-party-cask","tap":"third-party/tap","name":[],"desc":null,"homepage":"https://brew.sh/","url":"https://brew.sh/ThirdParty.dmg","appcast":null,"version":"1.2.3","installed":"1.2.3","outdated":false,"sha256":"8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b","artifacts":[["ThirdParty.app"]],"caveats":null,"depends_on":{},"conflicts_with":null,"container":null,"auto_updates":null}]
|
[
|
||||||
|
{
|
||||||
|
"token": "local-caffeine",
|
||||||
|
"full_token": "local-caffeine",
|
||||||
|
"tap": "homebrew/cask",
|
||||||
|
"name": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"desc": null,
|
||||||
|
"homepage": "https://brew.sh/",
|
||||||
|
"url": "file:///usr/local/Homebrew/Library/Homebrew/test/support/fixtures/cask/caffeine.zip",
|
||||||
|
"appcast": null,
|
||||||
|
"version": "1.2.3",
|
||||||
|
"installed": "1.2.3",
|
||||||
|
"outdated": false,
|
||||||
|
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
|
||||||
|
"artifacts": [
|
||||||
|
[
|
||||||
|
"Caffeine.app"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"caveats": null,
|
||||||
|
"depends_on": {
|
||||||
|
},
|
||||||
|
"conflicts_with": null,
|
||||||
|
"container": null,
|
||||||
|
"auto_updates": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "local-transmission",
|
||||||
|
"full_token": "local-transmission",
|
||||||
|
"tap": "homebrew/cask",
|
||||||
|
"name": [
|
||||||
|
"Transmission"
|
||||||
|
],
|
||||||
|
"desc": "BitTorrent client",
|
||||||
|
"homepage": "https://transmissionbt.com/",
|
||||||
|
"url": "file:///usr/local/Homebrew/Library/Homebrew/test/support/fixtures/cask/transmission-2.61.dmg",
|
||||||
|
"appcast": null,
|
||||||
|
"version": "2.61",
|
||||||
|
"installed": "2.61",
|
||||||
|
"outdated": false,
|
||||||
|
"sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68",
|
||||||
|
"artifacts": [
|
||||||
|
[
|
||||||
|
"Transmission.app"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"caveats": null,
|
||||||
|
"depends_on": {
|
||||||
|
},
|
||||||
|
"conflicts_with": null,
|
||||||
|
"container": null,
|
||||||
|
"auto_updates": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "third-party-cask",
|
||||||
|
"full_token": "third-party/tap/third-party-cask",
|
||||||
|
"tap": "third-party/tap",
|
||||||
|
"name": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"desc": null,
|
||||||
|
"homepage": "https://brew.sh/",
|
||||||
|
"url": "https://brew.sh/ThirdParty.dmg",
|
||||||
|
"appcast": null,
|
||||||
|
"version": "1.2.3",
|
||||||
|
"installed": "1.2.3",
|
||||||
|
"outdated": false,
|
||||||
|
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b",
|
||||||
|
"artifacts": [
|
||||||
|
[
|
||||||
|
"ThirdParty.app"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"caveats": null,
|
||||||
|
"depends_on": {
|
||||||
|
},
|
||||||
|
"conflicts_with": null,
|
||||||
|
"container": null,
|
||||||
|
"auto_updates": null
|
||||||
|
}
|
||||||
|
]
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ describe "brew outdated" do
|
|||||||
setup_test_formula "testball"
|
setup_test_formula "testball"
|
||||||
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
|
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
|
||||||
|
|
||||||
expected_json = {
|
expected_json = JSON.pretty_generate({
|
||||||
formulae: [{
|
formulae: [{
|
||||||
name: "testball",
|
name: "testball",
|
||||||
installed_versions: ["0.0.1"],
|
installed_versions: ["0.0.1"],
|
||||||
@ -19,7 +19,7 @@ describe "brew outdated" do
|
|||||||
pinned_version: nil,
|
pinned_version: nil,
|
||||||
}],
|
}],
|
||||||
casks: [],
|
casks: [],
|
||||||
}.to_json
|
})
|
||||||
|
|
||||||
expect { brew "outdated", "--json=v2" }
|
expect { brew "outdated", "--json=v2" }
|
||||||
.to output("#{expected_json}\n").to_stdout
|
.to output("#{expected_json}\n").to_stdout
|
||||||
|
@ -235,7 +235,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
|
|||||||
brew "install", old_name
|
brew "install", old_name
|
||||||
|
|
||||||
(tap_path/"Formula/#{old_name}.rb").unlink
|
(tap_path/"Formula/#{old_name}.rb").unlink
|
||||||
(tap_path/"formula_renames.json").write JSON.generate(old_name => new_name)
|
(tap_path/"formula_renames.json").write JSON.pretty_generate(old_name => new_name)
|
||||||
|
|
||||||
system "git", "add", "--all"
|
system "git", "add", "--all"
|
||||||
system "git", "commit", "-m",
|
system "git", "commit", "-m",
|
||||||
|
@ -193,7 +193,7 @@ module GitHub
|
|||||||
data_tmpfile = nil
|
data_tmpfile = nil
|
||||||
if data
|
if data
|
||||||
begin
|
begin
|
||||||
data = JSON.generate data
|
data = JSON.pretty_generate data
|
||||||
data_tmpfile = Tempfile.new("github_api_post", HOMEBREW_TEMP)
|
data_tmpfile = Tempfile.new("github_api_post", HOMEBREW_TEMP)
|
||||||
rescue JSON::ParserError => e
|
rescue JSON::ParserError => e
|
||||||
raise Error, "Failed to parse JSON request:\n#{e.message}\n#{data}", e.backtrace
|
raise Error, "Failed to parse JSON request:\n#{e.message}\n#{data}", e.backtrace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user