dev-cmd: use more and cleanup new args APIs.
This commit is contained in:
		
							parent
							
								
									a7fe0ed847
								
							
						
					
					
						commit
						e3ac94fc5d
					
				@ -79,12 +79,12 @@ module Homebrew
 | 
			
		||||
    ENV.activate_extensions!
 | 
			
		||||
    ENV.setup_build_environment
 | 
			
		||||
 | 
			
		||||
    if Homebrew.args.named.blank?
 | 
			
		||||
    if args.no_named?
 | 
			
		||||
      ff = Formula
 | 
			
		||||
      files = Tap.map(&:formula_dir)
 | 
			
		||||
    else
 | 
			
		||||
      ff = Homebrew.args.resolved_formulae
 | 
			
		||||
      files = Homebrew.args.resolved_formulae.map(&:path)
 | 
			
		||||
      ff = args.resolved_formulae
 | 
			
		||||
      files = args.resolved_formulae.map(&:path)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    only_cops = args.only_cops
 | 
			
		||||
 | 
			
		||||
@ -79,6 +79,7 @@ module Homebrew
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      conflicts "--no-rebuild", "--keep-old"
 | 
			
		||||
      min_named 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -86,10 +87,9 @@ module Homebrew
 | 
			
		||||
    bottle_args.parse
 | 
			
		||||
 | 
			
		||||
    return merge if args.merge?
 | 
			
		||||
    raise KegUnspecifiedError if args.remaining.empty?
 | 
			
		||||
 | 
			
		||||
    ensure_relocation_formulae_installed! unless args.skip_relocation?
 | 
			
		||||
    Homebrew.args.resolved_formulae.each do |f|
 | 
			
		||||
    args.resolved_formulae.each do |f|
 | 
			
		||||
      bottle_formula f
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
@ -435,10 +435,7 @@ module Homebrew
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def merge
 | 
			
		||||
    write = args.write?
 | 
			
		||||
    raise UsageError, "--merge requires a JSON file path argument" if Homebrew.args.named.blank?
 | 
			
		||||
 | 
			
		||||
    bottles_hash = Homebrew.args.named.reduce({}) do |hash, json_file|
 | 
			
		||||
    bottles_hash = args.named.reduce({}) do |hash, json_file|
 | 
			
		||||
      hash.deep_merge(JSON.parse(IO.read(json_file))) do |key, first, second|
 | 
			
		||||
        if key == "cellar"
 | 
			
		||||
          # Prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation
 | 
			
		||||
@ -478,7 +475,7 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
      output = bottle_output bottle
 | 
			
		||||
 | 
			
		||||
      if write
 | 
			
		||||
      if args.write?
 | 
			
		||||
        path = Pathname.new((HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]).to_s)
 | 
			
		||||
        update_or_add = nil
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -116,7 +116,7 @@ module Homebrew
 | 
			
		||||
    # Use the user's browser, too.
 | 
			
		||||
    ENV["BROWSER"] = ENV["HOMEBREW_BROWSER"]
 | 
			
		||||
 | 
			
		||||
    formula = Homebrew.args.formulae.first
 | 
			
		||||
    formula = args.formulae.first
 | 
			
		||||
 | 
			
		||||
    if formula
 | 
			
		||||
      tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula)
 | 
			
		||||
@ -315,7 +315,7 @@ module Homebrew
 | 
			
		||||
    new_formula_version = formula_version(formula, requested_spec, new_contents)
 | 
			
		||||
 | 
			
		||||
    if !new_mirrors && !formula_spec.mirrors.empty?
 | 
			
		||||
      if Homebrew.args.force?
 | 
			
		||||
      if args.force?
 | 
			
		||||
        opoo "#{formula}: Removing all mirrors because a --mirror= argument was not specified."
 | 
			
		||||
      else
 | 
			
		||||
        odie <<~EOS
 | 
			
		||||
@ -433,7 +433,7 @@ module Homebrew
 | 
			
		||||
      contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read }
 | 
			
		||||
      contents.extend(StringInreplaceExtension)
 | 
			
		||||
      replacement_pairs.each do |old, new|
 | 
			
		||||
        ohai "replace #{old.inspect} with #{new.inspect}" unless Homebrew.args.quiet?
 | 
			
		||||
        ohai "replace #{old.inspect} with #{new.inspect}" unless args.quiet?
 | 
			
		||||
        raise "No old value for new value #{new}! Did you pass the wrong arguments?" unless old
 | 
			
		||||
 | 
			
		||||
        contents.gsub!(old, new)
 | 
			
		||||
@ -445,7 +445,7 @@ module Homebrew
 | 
			
		||||
    else
 | 
			
		||||
      Utils::Inreplace.inreplace(path) do |s|
 | 
			
		||||
        replacement_pairs.each do |old, new|
 | 
			
		||||
          ohai "replace #{old.inspect} with #{new.inspect}" unless Homebrew.args.quiet?
 | 
			
		||||
          ohai "replace #{old.inspect} with #{new.inspect}" unless args.quiet?
 | 
			
		||||
          raise "No old value for new value #{new}! Did you pass the wrong arguments?" unless old
 | 
			
		||||
 | 
			
		||||
          s.gsub!(old, new)
 | 
			
		||||
@ -485,11 +485,11 @@ module Homebrew
 | 
			
		||||
      #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")}
 | 
			
		||||
    EOS
 | 
			
		||||
    error_message = "Duplicate PRs should not be opened. Use --force to override this error."
 | 
			
		||||
    if Homebrew.args.force? && !Homebrew.args.quiet?
 | 
			
		||||
    if args.force? && !args.quiet?
 | 
			
		||||
      opoo duplicates_message
 | 
			
		||||
    elsif !Homebrew.args.force? && Homebrew.args.quiet?
 | 
			
		||||
    elsif !args.force? && args.quiet?
 | 
			
		||||
      odie error_message
 | 
			
		||||
    elsif !Homebrew.args.force?
 | 
			
		||||
    elsif !args.force?
 | 
			
		||||
      odie <<~EOS
 | 
			
		||||
        #{duplicates_message.chomp}
 | 
			
		||||
        #{error_message}
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ module Homebrew
 | 
			
		||||
    # user path, too.
 | 
			
		||||
    ENV["PATH"] = ENV["HOMEBREW_PATH"]
 | 
			
		||||
 | 
			
		||||
    formulae = Homebrew.args.formulae
 | 
			
		||||
    formulae = args.formulae
 | 
			
		||||
    raise FormulaUnspecifiedError if formulae.empty?
 | 
			
		||||
 | 
			
		||||
    formula = formulae.first
 | 
			
		||||
@ -64,7 +64,7 @@ module Homebrew
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if args.dry_run?
 | 
			
		||||
      ohai "replace #{old.inspect} with #{replacement.inspect}" unless Homebrew.args.quiet?
 | 
			
		||||
      ohai "replace #{old.inspect} with #{replacement.inspect}" unless args.quiet?
 | 
			
		||||
    else
 | 
			
		||||
      Utils::Inreplace.inreplace(formula.path) do |s|
 | 
			
		||||
        s.gsub!(old, replacement)
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ module Homebrew
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      conflicts "--autotools", "--cmake", "--go", "--meson", "--perl", "--python", "--rust"
 | 
			
		||||
      max_named 1
 | 
			
		||||
      named 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -57,12 +57,10 @@ module Homebrew
 | 
			
		||||
  def create
 | 
			
		||||
    create_args.parse
 | 
			
		||||
 | 
			
		||||
    raise UsageError if ARGV.named.empty?
 | 
			
		||||
 | 
			
		||||
    # Ensure that the cache exists so we can fetch the tarball
 | 
			
		||||
    HOMEBREW_CACHE.mkpath
 | 
			
		||||
 | 
			
		||||
    url = ARGV.named.first # Pull the first (and only) url from ARGV
 | 
			
		||||
    url = args.named.first # Pull the first (and only) url from ARGV
 | 
			
		||||
 | 
			
		||||
    version = args.set_version
 | 
			
		||||
    name = args.set_name
 | 
			
		||||
 | 
			
		||||
@ -32,10 +32,10 @@ module Homebrew
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # If no brews are listed, open the project root in an editor.
 | 
			
		||||
    paths = [HOMEBREW_REPOSITORY] if ARGV.named.empty?
 | 
			
		||||
    paths = [HOMEBREW_REPOSITORY] if args.no_named?
 | 
			
		||||
 | 
			
		||||
    # Don't use ARGV.formulae as that will throw if the file doesn't parse
 | 
			
		||||
    paths ||= ARGV.named.map do |name|
 | 
			
		||||
    # Don't use args.formulae as that will throw if the file doesn't parse
 | 
			
		||||
    paths ||= args.named.map do |name|
 | 
			
		||||
      path = Formulary.path(name)
 | 
			
		||||
      raise FormulaUnavailableError, name if !path.file? && !args.force?
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -91,18 +91,15 @@ module Homebrew
 | 
			
		||||
             description: "Extract the specified <version> of <formula> instead of the most recent."
 | 
			
		||||
      switch :force
 | 
			
		||||
      switch :debug
 | 
			
		||||
      max_named 2
 | 
			
		||||
      named 2
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def extract
 | 
			
		||||
    extract_args.parse
 | 
			
		||||
 | 
			
		||||
    # Expect exactly two named arguments: formula and tap
 | 
			
		||||
    raise UsageError, "This command requires formula and tap arguments" if args.remaining.length != 2
 | 
			
		||||
 | 
			
		||||
    if args.remaining.first !~ HOMEBREW_TAP_FORMULA_REGEX
 | 
			
		||||
      name = args.remaining.first.downcase
 | 
			
		||||
    if args.named.first !~ HOMEBREW_TAP_FORMULA_REGEX
 | 
			
		||||
      name = args.named.first.downcase
 | 
			
		||||
      source_tap = CoreTap.instance
 | 
			
		||||
    else
 | 
			
		||||
      name = Regexp.last_match(3).downcase
 | 
			
		||||
@ -110,7 +107,7 @@ module Homebrew
 | 
			
		||||
      raise TapFormulaUnavailableError.new(source_tap, name) unless source_tap.installed?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    destination_tap = Tap.fetch(args.remaining.second)
 | 
			
		||||
    destination_tap = Tap.fetch(args.named.second)
 | 
			
		||||
    unless ARGV.homebrew_developer?
 | 
			
		||||
      odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap?
 | 
			
		||||
      odie "Cannot extract formula to the same tap!" if destination_tap == source_tap
 | 
			
		||||
@ -190,7 +187,7 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
    path = destination_tap.path/"Formula/#{name}@#{version}.rb"
 | 
			
		||||
    if path.exist?
 | 
			
		||||
      unless Homebrew.args.force?
 | 
			
		||||
      unless args.force?
 | 
			
		||||
        odie <<~EOS
 | 
			
		||||
          Destination formula already exists: #{path}
 | 
			
		||||
          To overwrite it and continue anyways, run:
 | 
			
		||||
 | 
			
		||||
@ -15,14 +15,13 @@ module Homebrew
 | 
			
		||||
      EOS
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      min_named :formula
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def formula
 | 
			
		||||
    formula_args.parse
 | 
			
		||||
 | 
			
		||||
    raise FormulaUnspecifiedError if Homebrew.args.named.blank?
 | 
			
		||||
 | 
			
		||||
    Homebrew.args.resolved_formulae.each { |f| puts f.path }
 | 
			
		||||
    args.resolved_formulae.each { |f| puts f.path }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -33,10 +33,10 @@ module Homebrew
 | 
			
		||||
    linkage_args.parse
 | 
			
		||||
 | 
			
		||||
    CacheStoreDatabase.use(:linkage) do |db|
 | 
			
		||||
      kegs = if Homebrew.args.kegs.empty?
 | 
			
		||||
      kegs = if args.kegs.empty?
 | 
			
		||||
        Formula.installed.map(&:opt_or_installed_prefix_keg).reject(&:nil?)
 | 
			
		||||
      else
 | 
			
		||||
        Homebrew.args.kegs
 | 
			
		||||
        args.kegs
 | 
			
		||||
      end
 | 
			
		||||
      kegs.each do |keg|
 | 
			
		||||
        ohai "Checking #{keg.name} linkage" if kegs.size > 1
 | 
			
		||||
 | 
			
		||||
@ -15,19 +15,18 @@ module Homebrew
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      hide_from_man_page!
 | 
			
		||||
      min_named :formula
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def mirror
 | 
			
		||||
    mirror_args.parse
 | 
			
		||||
 | 
			
		||||
    raise FormulaUnspecifiedError if args.remaining.empty?
 | 
			
		||||
 | 
			
		||||
    bintray_user = ENV["HOMEBREW_BINTRAY_USER"]
 | 
			
		||||
    bintray_key = ENV["HOMEBREW_BINTRAY_KEY"]
 | 
			
		||||
    raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key
 | 
			
		||||
 | 
			
		||||
    Homebrew.args.formulae.each do |f|
 | 
			
		||||
    args.formulae.each do |f|
 | 
			
		||||
      bintray_package = Utils::Bottles::Bintray.package f.name
 | 
			
		||||
      bintray_repo_url = "https://api.bintray.com/packages/homebrew/mirror"
 | 
			
		||||
      package_url = "#{bintray_repo_url}/#{bintray_package}"
 | 
			
		||||
 | 
			
		||||
@ -62,6 +62,7 @@ module Homebrew
 | 
			
		||||
             description: "Pull the bottle block commit from the specified <user> on GitHub."
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      min_named 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -70,10 +71,6 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
    pull_args.parse
 | 
			
		||||
 | 
			
		||||
    if ARGV.named.empty?
 | 
			
		||||
      raise UsageError, "This command requires at least one argument containing a URL or pull request number"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Passthrough Git environment variables for e.g. git am
 | 
			
		||||
    ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] if ENV["HOMEBREW_GIT_NAME"]
 | 
			
		||||
    ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"] if ENV["HOMEBREW_GIT_EMAIL"]
 | 
			
		||||
@ -96,7 +93,7 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
    tap = nil
 | 
			
		||||
 | 
			
		||||
    ARGV.named.each do |arg|
 | 
			
		||||
    args.named.each do |arg|
 | 
			
		||||
      arg = "#{CoreTap.instance.default_remote}/pull/#{arg}" if arg.to_i.positive?
 | 
			
		||||
      if (testing_match = arg.match %r{/job/Homebrew.*Testing/(\d+)})
 | 
			
		||||
        tap = ARGV.value("tap")
 | 
			
		||||
 | 
			
		||||
@ -23,13 +23,13 @@ module Homebrew
 | 
			
		||||
  def release_notes
 | 
			
		||||
    release_notes_args.parse
 | 
			
		||||
 | 
			
		||||
    previous_tag = ARGV.named.first
 | 
			
		||||
    previous_tag = args.named.first
 | 
			
		||||
    previous_tag ||= Utils.popen_read(
 | 
			
		||||
      "git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname"
 | 
			
		||||
    ).lines.first.chomp
 | 
			
		||||
    odie "Could not find any previous tags!" unless previous_tag
 | 
			
		||||
 | 
			
		||||
    end_ref = ARGV.named.second || "origin/master"
 | 
			
		||||
    end_ref = args.named.second || "origin/master"
 | 
			
		||||
 | 
			
		||||
    [previous_tag, end_ref].each do |ref|
 | 
			
		||||
      next if quiet_system "git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--verify", "--quiet", ref
 | 
			
		||||
 | 
			
		||||
@ -15,16 +15,14 @@ module Homebrew
 | 
			
		||||
      EOS
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      max_named 1
 | 
			
		||||
      named 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def tap_new
 | 
			
		||||
    tap_new_args.parse
 | 
			
		||||
 | 
			
		||||
    raise UsageError, "This command requires a tap argument" if ARGV.named.empty?
 | 
			
		||||
 | 
			
		||||
    tap = Tap.fetch(ARGV.named.first)
 | 
			
		||||
    tap = Tap.fetch(args.named.first)
 | 
			
		||||
    titleized_user = tap.user.dup
 | 
			
		||||
    titleized_repo = tap.repo.dup
 | 
			
		||||
    titleized_user[0] = titleized_user[0].upcase
 | 
			
		||||
 | 
			
		||||
@ -28,17 +28,16 @@ module Homebrew
 | 
			
		||||
      switch :verbose
 | 
			
		||||
      switch :debug
 | 
			
		||||
      conflicts "--devel", "--HEAD"
 | 
			
		||||
      min_named :formula
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test
 | 
			
		||||
    test_args.parse
 | 
			
		||||
 | 
			
		||||
    raise FormulaUnspecifiedError if ARGV.named.empty?
 | 
			
		||||
 | 
			
		||||
    require "formula_assertions"
 | 
			
		||||
 | 
			
		||||
    Homebrew.args.resolved_formulae.each do |f|
 | 
			
		||||
    args.resolved_formulae.each do |f|
 | 
			
		||||
      # Cannot test uninstalled formulae
 | 
			
		||||
      unless f.latest_version_installed?
 | 
			
		||||
        ofail "Testing requires the latest version of #{f.full_name}"
 | 
			
		||||
@ -52,7 +51,7 @@ module Homebrew
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      # Don't test unlinked formulae
 | 
			
		||||
      if !Homebrew.args.force? && !f.keg_only? && !f.linked?
 | 
			
		||||
      if !args.force? && !f.keg_only? && !f.linked?
 | 
			
		||||
        ofail "#{f.full_name} is not linked"
 | 
			
		||||
        next
 | 
			
		||||
      end
 | 
			
		||||
@ -75,19 +74,19 @@ module Homebrew
 | 
			
		||||
      env = ENV.to_hash
 | 
			
		||||
 | 
			
		||||
      begin
 | 
			
		||||
        args = %W[
 | 
			
		||||
        exec_args = %W[
 | 
			
		||||
          #{RUBY_PATH}
 | 
			
		||||
          -W0
 | 
			
		||||
          -I #{$LOAD_PATH.join(File::PATH_SEPARATOR)}
 | 
			
		||||
          --
 | 
			
		||||
          #{HOMEBREW_LIBRARY_PATH}/test.rb
 | 
			
		||||
          #{f.path}
 | 
			
		||||
        ].concat(Homebrew.args.options_only)
 | 
			
		||||
        ].concat(args.options_only)
 | 
			
		||||
 | 
			
		||||
        if f.head?
 | 
			
		||||
          args << "--HEAD"
 | 
			
		||||
          exec_args << "--HEAD"
 | 
			
		||||
        elsif f.devel?
 | 
			
		||||
          args << "--devel"
 | 
			
		||||
          exec_args << "--devel"
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        Utils.safe_fork do
 | 
			
		||||
@ -102,9 +101,9 @@ module Homebrew
 | 
			
		||||
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/homebrew/locks")
 | 
			
		||||
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/log")
 | 
			
		||||
            sandbox.allow_write_path(HOMEBREW_PREFIX/"var/run")
 | 
			
		||||
            sandbox.exec(*args)
 | 
			
		||||
            sandbox.exec(*exec_args)
 | 
			
		||||
          else
 | 
			
		||||
            exec(*args)
 | 
			
		||||
            exec(*exec_args)
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user