From f3e34230adbf8d66632b4e2dffe6395c69f57c2a Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 21 Jul 2022 16:41:15 +0200 Subject: [PATCH] Add `--variations` option to `brew info` --- Library/Homebrew/cask/cask.rb | 8 ++++---- Library/Homebrew/cmd/info.rb | 11 +++++++++++ Library/Homebrew/formula.rb | 10 +++++----- Library/Homebrew/formula.rbi | 1 + Library/Homebrew/utils/bottles.rb | 1 + completions/bash/brew | 2 ++ completions/fish/brew.fish | 2 ++ completions/zsh/_brew | 2 ++ docs/Manpage.md | 2 ++ manpages/brew.1 | 4 ++++ 10 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 01dd15293b..955cad92df 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -219,7 +219,7 @@ module Cask end alias == eql? - def to_hash + def to_h { "token" => token, "full_token" => full_name, @@ -243,8 +243,8 @@ module Cask } end - def to_h - hash = to_hash + def to_hash_with_variations + hash = to_h variations = {} hash_keys_to_skip = %w[outdated installed versions] @@ -260,7 +260,7 @@ module Cask refresh - to_hash.each do |key, value| + to_h.each do |key, value| next if hash_keys_to_skip.include? key next if value.to_s == hash[key].to_s diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 0fe8851a56..d06a6dada9 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -61,6 +61,9 @@ module Homebrew switch "--all", depends_on: "--json", description: "Print JSON of all available formulae." + switch "--variations", + depends_on: "--json", + description: "Include the variations hash in each formula's JSON output." switch "-v", "--verbose", description: "Show more verbose analytics data for ." switch "--formula", "--formulae", @@ -202,6 +205,8 @@ module Homebrew if args.bottle? formulae.map(&:to_recursive_bottle_hash) + elsif args.variations? + formulae.map(&:to_hash_with_variations) else formulae.map(&:to_hash) end @@ -216,6 +221,12 @@ module Homebrew if args.bottle? { "formulae" => formulae.map(&:to_recursive_bottle_hash) } + elsif args.variations? + opoo "a" + { + "formulae" => formulae.map(&:to_hash_with_variations), + "casks" => casks.map(&:to_hash_with_variations), + } else { "formulae" => formulae.map(&:to_hash), diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 86664d92fe..1e8086d8e0 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1909,7 +1909,7 @@ class Formula end # @private - def to_hash_without_variations + def to_hash dependencies = deps hsh = { @@ -2006,15 +2006,15 @@ class Formula end # @private - def to_hash - hash = to_hash_without_variations + def to_hash_with_variations + hash = to_hash variations = {} os_versions = [*MacOSVersions::SYMBOLS.keys, :linux] if path.exist? && self.class.on_system_blocks_exist? formula_contents = path.read - [:arm64, :x86_64].each do |arch| + [:arm, :intel].each do |arch| os_versions.each do |os_name| bottle_tag = Utils::Bottles::Tag.new(system: os_name, arch: arch) next unless bottle_tag.valid_combination? @@ -2028,7 +2028,7 @@ class Formula variations_formula = variations_formula_class.new(name, path, :stable, alias_path: alias_path, force_bottle: force_bottle) - variations_formula.to_hash_without_variations.each do |key, value| + variations_formula.to_hash.each do |key, value| next if value.to_s == hash[key].to_s variations[bottle_tag.to_sym] ||= {} diff --git a/Library/Homebrew/formula.rbi b/Library/Homebrew/formula.rbi index f77f4c0c50..fc8d6c255c 100644 --- a/Library/Homebrew/formula.rbi +++ b/Library/Homebrew/formula.rbi @@ -49,6 +49,7 @@ class Formula def env; end def conflicts; end + def self.on_system_blocks_exist?; end # This method is included by `OnSystem` def self.on_macos(&block); end end diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 02042beb8a..6ffcb815b9 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -169,6 +169,7 @@ module Utils [system, arch].hash end + sig { returns(Symbol) } def standardized_arch return :x86_64 if [:x86_64, :intel].include? arch return :arm64 if [:arm64, :arm].include? arch diff --git a/completions/bash/brew b/completions/bash/brew index 52f38dc610..86abb433c2 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -312,6 +312,7 @@ _brew_abv() { --installed --json --quiet + --variations --verbose " return @@ -1044,6 +1045,7 @@ _brew_info() { --installed --json --quiet + --variations --verbose " return diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index a2388a139b..d1ba1881af 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -307,6 +307,7 @@ __fish_brew_complete_arg 'abv' -l help -d 'Show this message' __fish_brew_complete_arg 'abv' -l installed -d 'Print JSON of formulae that are currently installed' __fish_brew_complete_arg 'abv' -l json -d 'Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew' __fish_brew_complete_arg 'abv' -l quiet -d 'Make some output more quiet' +__fish_brew_complete_arg 'abv' -l variations -d 'Include the variations hash in each formula\'s JSON output' __fish_brew_complete_arg 'abv' -l verbose -d 'Show more verbose analytics data for formula' __fish_brew_complete_arg 'abv; and not __fish_seen_argument -l cask -l casks' -a '(__fish_brew_suggest_formulae_all)' __fish_brew_complete_arg 'abv; and not __fish_seen_argument -l formula -l formulae' -a '(__fish_brew_suggest_casks_all)' @@ -757,6 +758,7 @@ __fish_brew_complete_arg 'info' -l help -d 'Show this message' __fish_brew_complete_arg 'info' -l installed -d 'Print JSON of formulae that are currently installed' __fish_brew_complete_arg 'info' -l json -d 'Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew' __fish_brew_complete_arg 'info' -l quiet -d 'Make some output more quiet' +__fish_brew_complete_arg 'info' -l variations -d 'Include the variations hash in each formula\'s JSON output' __fish_brew_complete_arg 'info' -l verbose -d 'Show more verbose analytics data for formula' __fish_brew_complete_arg 'info; and not __fish_seen_argument -l cask -l casks' -a '(__fish_brew_suggest_formulae_all)' __fish_brew_complete_arg 'info; and not __fish_seen_argument -l formula -l formulae' -a '(__fish_brew_suggest_casks_all)' diff --git a/completions/zsh/_brew b/completions/zsh/_brew index aa175d3830..7c33b10012 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -382,6 +382,7 @@ _brew_abv() { '(--all)--installed[Print JSON of formulae that are currently installed]' \ '--json[Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew]' \ '--quiet[Make some output more quiet]' \ + '--variations[Include the variations hash in each formula'\''s JSON output]' \ '--verbose[Show more verbose analytics data for formula]' \ - formula \ '(--cask)--formula[Treat all named arguments as formulae]' \ @@ -931,6 +932,7 @@ _brew_info() { '(--all)--installed[Print JSON of formulae that are currently installed]' \ '--json[Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew]' \ '--quiet[Make some output more quiet]' \ + '--variations[Include the variations hash in each formula'\''s JSON output]' \ '--verbose[Show more verbose analytics data for formula]' \ - formula \ '(--cask)--formula[Treat all named arguments as formulae]' \ diff --git a/docs/Manpage.md b/docs/Manpage.md index f74003edb1..57e1e3b4ef 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -295,6 +295,8 @@ If a *`formula`* or *`cask`* is provided, show summary of information about it. Print JSON of formulae that are currently installed. * `--all`: Print JSON of all available formulae. +* `--variations`: + Include the variations hash in each formula's JSON output. * `-v`, `--verbose`: Show more verbose analytics data for *`formula`*. * `--formula`: diff --git a/manpages/brew.1 b/manpages/brew.1 index 87c2999563..760aa819c6 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -385,6 +385,10 @@ Print JSON of formulae that are currently installed\. Print JSON of all available formulae\. . .TP +\fB\-\-variations\fR +Include the variations hash in each formula\'s JSON output\. +. +.TP \fB\-v\fR, \fB\-\-verbose\fR Show more verbose analytics data for \fIformula\fR\. .