Migrate livecheck to Homebrew/brew
Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com> Co-authored-by: Thierry Moisan <thierry.moisan@gmail.com> Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com> Co-authored-by: Maxim Belkin <maxim.belkin@gmail.com> Co-authored-by: Issy Long <me@issyl0.co.uk> Co-authored-by: Mike McQuaid <mike@mikemcquaid.com> Co-authored-by: Seeker <meaningseeking@protonmail.com>
This commit is contained in:
		
							parent
							
								
									44c826eae1
								
							
						
					
					
						commit
						e5fe57c1fe
					
				
							
								
								
									
										75
									
								
								Library/Homebrew/dev-cmd/livecheck.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								Library/Homebrew/dev-cmd/livecheck.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,75 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "cli/parser"
 | 
			
		||||
require "formula"
 | 
			
		||||
require "livecheck/livecheck"
 | 
			
		||||
require "livecheck/strategy"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  module_function
 | 
			
		||||
 | 
			
		||||
  WATCHLIST_PATH = (
 | 
			
		||||
    ENV["HOMEBREW_LIVECHECK_WATCHLIST"] ||
 | 
			
		||||
    Pathname.new(Dir.home)/".brew_livecheck_watchlist"
 | 
			
		||||
  ).freeze
 | 
			
		||||
 | 
			
		||||
  def livecheck_args
 | 
			
		||||
    Homebrew::CLI::Parser.new do
 | 
			
		||||
      usage_banner <<~EOS
 | 
			
		||||
        `livecheck` [<formulae>]
 | 
			
		||||
 | 
			
		||||
        Check for newer versions of formulae from upstream.
 | 
			
		||||
 | 
			
		||||
        If no formula argument is passed, the list of formulae to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST`
 | 
			
		||||
        or `~/.brew_livecheck_watchlist`.
 | 
			
		||||
      EOS
 | 
			
		||||
      switch "--full-name",
 | 
			
		||||
             description: "Print formulae with fully-qualified names."
 | 
			
		||||
      flag   "--tap=",
 | 
			
		||||
             description: "Check the formulae within the given tap, specified as <user>`/`<repo>."
 | 
			
		||||
      switch "--installed",
 | 
			
		||||
             description: "Check formulae that are currently installed."
 | 
			
		||||
      switch "--json",
 | 
			
		||||
             description: "Output informations in JSON format."
 | 
			
		||||
      switch "--all",
 | 
			
		||||
             description: "Check all available formulae."
 | 
			
		||||
      switch "--newer-only",
 | 
			
		||||
             description: "Show the latest version only if it's newer than the formula."
 | 
			
		||||
      conflicts "--debug", "--json"
 | 
			
		||||
      conflicts "--tap=", "--all", "--installed"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def livecheck
 | 
			
		||||
    args = livecheck_args.parse
 | 
			
		||||
 | 
			
		||||
    if args.debug? && args.verbose?
 | 
			
		||||
      puts args
 | 
			
		||||
      puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    formulae_to_check = if args.tap
 | 
			
		||||
      Tap.fetch(args.tap).formula_names.map { |name| Formula[name] }
 | 
			
		||||
    elsif args.installed?
 | 
			
		||||
      Formula.installed
 | 
			
		||||
    elsif args.all?
 | 
			
		||||
      Formula
 | 
			
		||||
    elsif args.formulae.present?
 | 
			
		||||
      args.formulae
 | 
			
		||||
    elsif File.exist?(WATCHLIST_PATH)
 | 
			
		||||
      begin
 | 
			
		||||
        WATCHLIST_PATH.read.lines.map do |line|
 | 
			
		||||
          next if line.start_with?("#")
 | 
			
		||||
 | 
			
		||||
          Formula[line.strip]
 | 
			
		||||
        end.compact
 | 
			
		||||
      rescue Errno::ENOENT => e
 | 
			
		||||
        onoe e
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    raise UsageError, "No formulae to check." if formulae_to_check.blank?
 | 
			
		||||
 | 
			
		||||
    Livecheck.livecheck_formulae(formulae_to_check, args)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -173,6 +173,11 @@ module Homebrew
 | 
			
		||||
        default_text: 'The "Beer Mug" emoji.',
 | 
			
		||||
        default:      "🍺",
 | 
			
		||||
      },
 | 
			
		||||
      HOMEBREW_LIVECHECK_WATCHLIST:       {
 | 
			
		||||
        description: "Use this file to get the list of default Formulae to check when no Formula argument " \
 | 
			
		||||
                     "is passed to `brew livecheck`",
 | 
			
		||||
        default:     "$HOME/.brew_livecheck_watchlist",
 | 
			
		||||
      },
 | 
			
		||||
      HOMEBREW_LOGS:                      {
 | 
			
		||||
        description:  "Use the specified directory to store log files.",
 | 
			
		||||
        default_text: "macOS: `$HOME/Library/Logs/Homebrew`, "\
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,7 @@ DEPRECATED_OFFICIAL_TAPS = %w[
 | 
			
		||||
  games
 | 
			
		||||
  gui
 | 
			
		||||
  head-only
 | 
			
		||||
  livecheck
 | 
			
		||||
  nginx
 | 
			
		||||
  php
 | 
			
		||||
  python
 | 
			
		||||
 | 
			
		||||
@ -75,6 +75,7 @@ RSpec/MultipleDescribes:
 | 
			
		||||
    - 'dev-cmd/formula_spec.rb'
 | 
			
		||||
    - 'dev-cmd/irb_spec.rb'
 | 
			
		||||
    - 'dev-cmd/linkage_spec.rb'
 | 
			
		||||
    - 'dev-cmd/livecheck_spec.rb'
 | 
			
		||||
    - 'dev-cmd/pull_spec.rb'
 | 
			
		||||
    - 'dev-cmd/ruby_spec.rb'
 | 
			
		||||
    - 'dev-cmd/sh_spec.rb'
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								Library/Homebrew/test/dev-cmd/livecheck_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Library/Homebrew/test/dev-cmd/livecheck_spec.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "cmd/shared_examples/args_parse"
 | 
			
		||||
 | 
			
		||||
describe "Homebrew.livecheck_args" do
 | 
			
		||||
  it_behaves_like "parseable arguments"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
describe "brew livecheck", :integration_test do
 | 
			
		||||
  it "reports the latest version of a Formula", :needs_network do
 | 
			
		||||
    content = <<~RUBY
 | 
			
		||||
      desc "Some test"
 | 
			
		||||
      homepage "https://github.com/Homebrew/brew"
 | 
			
		||||
      url "https://brew.sh/test-1.0.0.tgz"
 | 
			
		||||
    RUBY
 | 
			
		||||
    setup_test_formula("test", content)
 | 
			
		||||
 | 
			
		||||
    expect { brew "livecheck", "test" }
 | 
			
		||||
      .to output(/test : /).to_stdout
 | 
			
		||||
      .and not_to_output.to_stderr
 | 
			
		||||
      .and be_a_success
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -352,6 +352,17 @@ _brew_list() {
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_brew_livecheck() {
 | 
			
		||||
  local cur="${COMP_WORDS[COMP_CWORD]}"
 | 
			
		||||
  case "$cur" in
 | 
			
		||||
    -*)
 | 
			
		||||
      __brewcomp "--verbose --quiet --debug --full-name --tap --installed --json --all --newer-only --help"
 | 
			
		||||
      return
 | 
			
		||||
      ;;
 | 
			
		||||
  esac
 | 
			
		||||
  __brew_complete_formulae
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_brew_log() {
 | 
			
		||||
  # if git-completion is loaded, then we complete git-log options
 | 
			
		||||
  declare -F _git_log >/dev/null || return
 | 
			
		||||
@ -860,6 +871,7 @@ _brew() {
 | 
			
		||||
    irb)                        _brew_irb ;;
 | 
			
		||||
    link|ln)                    _brew_link ;;
 | 
			
		||||
    list|ls)                    _brew_list ;;
 | 
			
		||||
    livecheck)                  _brew_livecheck ;;
 | 
			
		||||
    log)                        _brew_log ;;
 | 
			
		||||
    man)                        _brew_man ;;
 | 
			
		||||
    missing)                    __brew_complete_formulae ;;
 | 
			
		||||
 | 
			
		||||
@ -446,6 +446,20 @@ __fish_brew_complete_arg 'list ls;
 | 
			
		||||
    ' -l multiple -d "Only show formulae with multiple versions"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__fish_brew_complete_cmd 'livecheck' "Check for newer versions of formulae from upstream"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck' -a '(__fish_brew_suggest_formulae_all)'
 | 
			
		||||
__fish_brew_complete_arg 'livecheck' -s v -l verbose    -d "Make some output more verbose"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck' -s q -l quiet      -d "Suppress any warnings"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck' -s d -l debug      -d "Display any debugging information"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck'      -l full-name  -d "Print formulae with fully-qualified name"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck'      -l tap        -d "Check the formulae within the given tap, specified as user/repo"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck'      -l installed  -d "Check formulae that are currently installed"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck'      -l json       -d "Output information in JSON format"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck'      -l all        -d "Check all available formulae"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck'      -l newer-only -d "Show the latest version only if it is newer than the formula"
 | 
			
		||||
__fish_brew_complete_arg 'livecheck' -s h -l help       -d "Show the help message"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__fish_brew_complete_cmd 'log' "Show git log for formula"
 | 
			
		||||
__fish_brew_complete_arg 'log' -a '(__fish_brew_suggest_formulae_all)'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -47,6 +47,7 @@ leaves
 | 
			
		||||
link
 | 
			
		||||
linkage
 | 
			
		||||
list
 | 
			
		||||
livecheck
 | 
			
		||||
ln
 | 
			
		||||
log
 | 
			
		||||
ls
 | 
			
		||||
 | 
			
		||||
@ -504,6 +504,23 @@ _brew_list() {
 | 
			
		||||
    '*:: :__brew_installed_formulae'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# brew livecheck [--verbose] [--quiet] [--debug] [--full-name] [--tap user/repo]
 | 
			
		||||
#                [--installed] [--json] [--all] [--newer-only] formulae
 | 
			
		||||
_brew_livecheck() {
 | 
			
		||||
  _arguments \
 | 
			
		||||
    '(--verbose,-v)'{--verbose,-v}'[Make some output more verbose]' \
 | 
			
		||||
    '(--quiet,-q)'{--quiet,-q}'[Suppress any warnings]' \
 | 
			
		||||
    '(--debug,-d)'{--debug,-d}'[Display any debugging information]' \
 | 
			
		||||
    '--full-name[Print formulae with fully-qualified name]' \
 | 
			
		||||
    '--tap[Check the formulae within the given tap, specified as user/repo]' \
 | 
			
		||||
    '--installed[Check formulae that are currently installed]' \
 | 
			
		||||
    '--json[Output information in JSON format]' \
 | 
			
		||||
    '--all[Check all available formulae]' \
 | 
			
		||||
    '--newer-only[Show the latest version only if it is newer than the formula]' \
 | 
			
		||||
    '(--help,-h)'{--help,-h}'[Show the help message]' \
 | 
			
		||||
    '*:: :__brew_formulae'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# brew log [git-log-options] formula ...:
 | 
			
		||||
_brew_log() {
 | 
			
		||||
  __brew_formulae
 | 
			
		||||
 | 
			
		||||
@ -992,6 +992,26 @@ provided, check all kegs. Raises an error if run on uninstalled formulae.
 | 
			
		||||
* `--cached`:
 | 
			
		||||
  Print the cached linkage values stored in `HOMEBREW_CACHE`, set by a previous `brew linkage` run.
 | 
			
		||||
 | 
			
		||||
### `livecheck` [*`formulae`*]
 | 
			
		||||
 | 
			
		||||
Check for newer versions of formulae from upstream.
 | 
			
		||||
 | 
			
		||||
If no formula argument is passed, the list of formulae to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST`
 | 
			
		||||
or `~/.brew_livecheck_watchlist`.
 | 
			
		||||
 | 
			
		||||
* `--full-name`:
 | 
			
		||||
  Print formulae with fully-qualified names.
 | 
			
		||||
* `--tap`:
 | 
			
		||||
  Check the formulae within the given tap, specified as *`user`*`/`*`repo`*.
 | 
			
		||||
* `--installed`:
 | 
			
		||||
  Check formulae that are currently installed.
 | 
			
		||||
* `--json`:
 | 
			
		||||
  Output informations in JSON format.
 | 
			
		||||
* `--all`:
 | 
			
		||||
  Check all available formulae.
 | 
			
		||||
* `--newer-only`:
 | 
			
		||||
  Show the latest version only if it's newer than the formula.
 | 
			
		||||
 | 
			
		||||
### `man` [*`options`*]
 | 
			
		||||
 | 
			
		||||
Generate Homebrew's manpages.
 | 
			
		||||
@ -1591,6 +1611,11 @@ For example, you might add something like the following to your ~/.profile, ~/.b
 | 
			
		||||
 | 
			
		||||
    *Default:* The "Beer Mug" emoji.
 | 
			
		||||
 | 
			
		||||
  * `HOMEBREW_LIVECHECK_WATCHLIST`:
 | 
			
		||||
    Use this file to get the list of default Formulae to check when no Formula argument is passed to `brew livecheck`
 | 
			
		||||
 | 
			
		||||
    *Default:* `$HOME/.brew_livecheck_watchlist`.
 | 
			
		||||
 | 
			
		||||
  * `HOMEBREW_LOGS`:
 | 
			
		||||
    Use the specified directory to store log files.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1362,6 +1362,36 @@ For every library that a keg references, print its dylib path followed by the bi
 | 
			
		||||
\fB\-\-cached\fR
 | 
			
		||||
Print the cached linkage values stored in \fBHOMEBREW_CACHE\fR, set by a previous \fBbrew linkage\fR run\.
 | 
			
		||||
.
 | 
			
		||||
.SS "\fBlivecheck\fR [\fIformulae\fR]"
 | 
			
		||||
Check for newer versions of formulae from upstream\.
 | 
			
		||||
.
 | 
			
		||||
.P
 | 
			
		||||
If no formula argument is passed, the list of formulae to check is taken from \fBHOMEBREW_LIVECHECK_WATCHLIST\fR or \fB~/\.brew_livecheck_watchlist\fR\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-full\-name\fR
 | 
			
		||||
Print formulae with fully\-qualified names\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-tap\fR
 | 
			
		||||
Check the formulae within the given tap, specified as \fIuser\fR\fB/\fR\fIrepo\fR\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-installed\fR
 | 
			
		||||
Check formulae that are currently installed\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-json\fR
 | 
			
		||||
Output informations in JSON format\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-all\fR
 | 
			
		||||
Check all available formulae\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fB\-\-newer\-only\fR
 | 
			
		||||
Show the latest version only if it\'s newer than the formula\.
 | 
			
		||||
.
 | 
			
		||||
.SS "\fBman\fR [\fIoptions\fR]"
 | 
			
		||||
Generate Homebrew\'s manpages\.
 | 
			
		||||
.
 | 
			
		||||
@ -2181,6 +2211,13 @@ Print this text before the installation summary of each successful build\.
 | 
			
		||||
\fIDefault:\fR The "Beer Mug" emoji\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fBHOMEBREW_LIVECHECK_WATCHLIST\fR
 | 
			
		||||
Use this file to get the list of default Formulae to check when no Formula argument is passed to \fBbrew livecheck\fR
 | 
			
		||||
.
 | 
			
		||||
.IP
 | 
			
		||||
\fIDefault:\fR \fB$HOME/\.brew_livecheck_watchlist\fR\.
 | 
			
		||||
.
 | 
			
		||||
.TP
 | 
			
		||||
\fBHOMEBREW_LOGS\fR
 | 
			
		||||
Use the specified directory to store log files\.
 | 
			
		||||
.
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user