Merge pull request #16937 from Homebrew/ported-cmds
Convert next batch of dev commands to use AbstractCommand
This commit is contained in:
commit
999ecf8b54
@ -17,7 +17,7 @@ module Homebrew
|
||||
|
||||
class << self
|
||||
sig { returns(String) }
|
||||
def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-")
|
||||
def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-").delete_suffix("-cmd")
|
||||
|
||||
# @return the AbstractCommand subclass associated with the brew CLI command name.
|
||||
sig { params(name: String).returns(T.nilable(T.class_of(AbstractCommand))) }
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "csv"
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "formula"
|
||||
@ -9,11 +9,9 @@ require "utils/pypi"
|
||||
require "cask/cask_loader"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def create_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class Create < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Generate a formula or, with `--cask`, a cask for the downloadable file at <URL>
|
||||
and open it in the editor. Homebrew will attempt to automatically derive the
|
||||
@ -67,24 +65,23 @@ module Homebrew
|
||||
|
||||
named_args :url, number: 1
|
||||
end
|
||||
end
|
||||
|
||||
# Create a formula from a tarball URL.
|
||||
sig { void }
|
||||
def create
|
||||
args = create_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
path = if args.cask?
|
||||
create_cask(args:)
|
||||
create_cask
|
||||
else
|
||||
create_formula(args:)
|
||||
create_formula
|
||||
end
|
||||
|
||||
exec_editor path
|
||||
end
|
||||
|
||||
sig { params(args: CLI::Args).returns(Pathname) }
|
||||
def create_cask(args:)
|
||||
private
|
||||
|
||||
sig { returns(Pathname) }
|
||||
def create_cask
|
||||
url = args.named.first
|
||||
name = if args.set_name.blank?
|
||||
stem = Pathname.new(url).stem.rpartition("=").last
|
||||
@ -155,8 +152,8 @@ module Homebrew
|
||||
cask_path
|
||||
end
|
||||
|
||||
sig { params(args: CLI::Args).returns(Pathname) }
|
||||
def create_formula(args:)
|
||||
sig { returns(Pathname) }
|
||||
def create_formula
|
||||
mode = if args.autotools?
|
||||
:autotools
|
||||
elsif args.cmake?
|
||||
@ -237,4 +234,6 @@ module Homebrew
|
||||
gots = $stdin.gets.chomp
|
||||
gots.empty? ? nil : gots
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "test_runner_formula"
|
||||
require "github_runner_matrix"
|
||||
|
||||
module Homebrew
|
||||
sig { returns(Homebrew::CLI::Parser) }
|
||||
def self.determine_test_runners_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class DetermineTestRunners < AbstractCommand
|
||||
cmd_args do
|
||||
usage_banner <<~EOS
|
||||
`determine-test-runners` {<testing-formulae> [<deleted-formulae>]|--all-supported}
|
||||
|
||||
@ -30,12 +31,9 @@ module Homebrew
|
||||
|
||||
hide_from_man_page!
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def self.determine_test_runners
|
||||
args = determine_test_runners_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
if args.no_named? && !args.all_supported?
|
||||
raise Homebrew::CLI::MinNamedArgumentsError, 1
|
||||
elsif args.all_supported? && !args.no_named?
|
||||
@ -59,4 +57,6 @@ module Homebrew
|
||||
f.puts("runners_present=#{runners.present?}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "utils/github"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def dispatch_build_bottle_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class DispatchBuildBottle < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Build bottles for these formulae with GitHub Actions.
|
||||
EOS
|
||||
@ -35,11 +34,9 @@ module Homebrew
|
||||
conflicts "--linux", "--linux-self-hosted"
|
||||
named_args :formula, min: 1
|
||||
end
|
||||
end
|
||||
|
||||
def dispatch_build_bottle
|
||||
args = dispatch_build_bottle_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
tap = Tap.fetch(args.tap || CoreTap.instance.name)
|
||||
user, repo = tap.full_name.split("/")
|
||||
ref = "master"
|
||||
@ -91,4 +88,6 @@ module Homebrew
|
||||
GitHub.workflow_dispatch_event(user, repo, workflow, ref, **inputs)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "cli/parser"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def edit_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class Edit < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Open a <formula>, <cask> or <tap> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
|
||||
or open the Homebrew repository for editing if no argument is provided.
|
||||
@ -26,8 +25,57 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :cask, :tap], without_api: true
|
||||
end
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
ENV["COLORTERM"] = ENV.fetch("HOMEBREW_COLORTERM", nil)
|
||||
|
||||
unless (HOMEBREW_REPOSITORY/".git").directory?
|
||||
odie <<~EOS
|
||||
Changes will be lost!
|
||||
The first time you `brew update`, all local changes will be lost; you should
|
||||
thus `brew update` before you `brew edit`!
|
||||
EOS
|
||||
end
|
||||
|
||||
paths = if args.named.empty?
|
||||
# Sublime requires opting into the project editing path,
|
||||
# as opposed to VS Code which will infer from the .vscode path
|
||||
if which_editor(silent: true) == "subl"
|
||||
["--project", "#{HOMEBREW_REPOSITORY}/.sublime/homebrew.sublime-project"]
|
||||
else
|
||||
# If no formulae are listed, open the project root in an editor.
|
||||
[HOMEBREW_REPOSITORY]
|
||||
end
|
||||
else
|
||||
expanded_paths = args.named.to_paths
|
||||
expanded_paths.each do |path|
|
||||
raise_with_message!(path, args.cask?) unless path.exist?
|
||||
end
|
||||
|
||||
if expanded_paths.any? do |path|
|
||||
!Homebrew::EnvConfig.no_install_from_api? &&
|
||||
!Homebrew::EnvConfig.no_env_hints? &&
|
||||
(core_formula_path?(path) || core_cask_path?(path) || core_formula_tap?(path) || core_cask_tap?(path))
|
||||
end
|
||||
opoo <<~EOS
|
||||
`brew install` ignores locally edited casks and formulae if
|
||||
HOMEBREW_NO_INSTALL_FROM_API is not set.
|
||||
EOS
|
||||
end
|
||||
expanded_paths
|
||||
end
|
||||
|
||||
if args.print_path?
|
||||
paths.each { puts _1 }
|
||||
return
|
||||
end
|
||||
|
||||
exec_editor(*paths)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { params(path: Pathname).returns(T::Boolean) }
|
||||
def core_formula_path?(path)
|
||||
path.fnmatch?("**/homebrew-core/Formula/**.rb", File::FNM_DOTMATCH)
|
||||
@ -80,54 +128,6 @@ module Homebrew
|
||||
Run #{Formatter.identifier(command)} to #{action}!
|
||||
EOS
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def edit
|
||||
args = edit_args.parse
|
||||
|
||||
ENV["COLORTERM"] = ENV.fetch("HOMEBREW_COLORTERM", nil)
|
||||
|
||||
unless (HOMEBREW_REPOSITORY/".git").directory?
|
||||
odie <<~EOS
|
||||
Changes will be lost!
|
||||
The first time you `brew update`, all local changes will be lost; you should
|
||||
thus `brew update` before you `brew edit`!
|
||||
EOS
|
||||
end
|
||||
|
||||
paths = if args.named.empty?
|
||||
# Sublime requires opting into the project editing path,
|
||||
# as opposed to VS Code which will infer from the .vscode path
|
||||
if which_editor(silent: true) == "subl"
|
||||
["--project", "#{HOMEBREW_REPOSITORY}/.sublime/homebrew.sublime-project"]
|
||||
else
|
||||
# If no formulae are listed, open the project root in an editor.
|
||||
[HOMEBREW_REPOSITORY]
|
||||
end
|
||||
else
|
||||
expanded_paths = args.named.to_paths
|
||||
expanded_paths.each do |path|
|
||||
raise_with_message!(path, args.cask?) unless path.exist?
|
||||
end
|
||||
|
||||
if expanded_paths.any? do |path|
|
||||
(core_formula_path?(path) || core_cask_path?(path) || core_formula_tap?(path) || core_cask_tap?(path)) &&
|
||||
!Homebrew::EnvConfig.no_install_from_api? &&
|
||||
!Homebrew::EnvConfig.no_env_hints?
|
||||
end
|
||||
opoo <<~EOS
|
||||
`brew install` ignores locally edited casks and formulae if
|
||||
HOMEBREW_NO_INSTALL_FROM_API is not set.
|
||||
EOS
|
||||
end
|
||||
expanded_paths
|
||||
end
|
||||
|
||||
if args.print_path?
|
||||
paths.each(&method(:puts))
|
||||
return
|
||||
end
|
||||
|
||||
exec_editor(*paths)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "utils/git"
|
||||
require "formulary"
|
||||
@ -8,11 +9,11 @@ require "software_spec"
|
||||
require "tap"
|
||||
|
||||
module Homebrew
|
||||
module DevCmd
|
||||
class Extract < AbstractCommand
|
||||
BOTTLE_BLOCK_REGEX = / bottle (?:do.+?end|:[a-z]+)\n\n/m
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.extract_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
usage_banner "`extract` [`--version=`] [`--force`] <formula> <tap>"
|
||||
description <<~EOS
|
||||
Look through repository history to find the most recent version of <formula> and
|
||||
@ -29,11 +30,9 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :tap], number: 2, without_api: true
|
||||
end
|
||||
end
|
||||
|
||||
def self.extract
|
||||
args = extract_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
if (tap_with_name = args.named.first&.then { Tap.with_formula_name(_1) })
|
||||
source_tap, name = tap_with_name
|
||||
else
|
||||
@ -149,9 +148,10 @@ module Homebrew
|
||||
path.write result
|
||||
end
|
||||
|
||||
# @private
|
||||
private
|
||||
|
||||
sig { params(repo: Pathname, name: String, file: Pathname, rev: String).returns(T.nilable(Formula)) }
|
||||
def self.formula_at_revision(repo, name, file, rev)
|
||||
def formula_at_revision(repo, name, file, rev)
|
||||
return if rev.empty?
|
||||
|
||||
contents = Utils::Git.last_revision_of_file(repo, file, before_commit: rev)
|
||||
@ -161,7 +161,7 @@ module Homebrew
|
||||
with_monkey_patch { Formulary.from_contents(name, file, contents, ignore_errors: true) }
|
||||
end
|
||||
|
||||
private_class_method def self.with_monkey_patch
|
||||
def with_monkey_patch
|
||||
# Since `method_defined?` is not a supported type guard, the use of `alias_method` below is not typesafe:
|
||||
BottleSpecification.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
@ -185,7 +185,10 @@ module Homebrew
|
||||
end
|
||||
|
||||
DependencyCollector.class_eval do
|
||||
T.unsafe(self).alias_method :old_parse_symbol_spec, :parse_symbol_spec if method_defined?(:parse_symbol_spec)
|
||||
if method_defined?(:parse_symbol_spec)
|
||||
T.unsafe(self).alias_method :old_parse_symbol_spec,
|
||||
:parse_symbol_spec
|
||||
end
|
||||
define_method(:parse_symbol_spec) do |*|
|
||||
# do nothing
|
||||
end
|
||||
@ -221,4 +224,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,32 +1,31 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "cli/parser"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def formula_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class FormulaCmd < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Display the path where <formula> is located.
|
||||
EOS
|
||||
|
||||
named_args :formula, min: 1, without_api: true
|
||||
end
|
||||
end
|
||||
|
||||
def formula
|
||||
args = formula_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
formula_paths = args.named.to_paths(only: :formula).select(&:exist?)
|
||||
if formula_paths.blank? && args.named
|
||||
.to_paths(only: :cask)
|
||||
.any?(&:exist?)
|
||||
odie "Found casks but did not find formulae!"
|
||||
end
|
||||
formula_paths.each(&method(:puts))
|
||||
formula_paths.each { puts _1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,16 +1,22 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "cask/cask"
|
||||
require "formula"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
module DevCmd
|
||||
class GenerateCaskApi < AbstractCommand
|
||||
CASK_JSON_TEMPLATE = <<~EOS
|
||||
---
|
||||
layout: cask_json
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def generate_cask_api_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Generate `homebrew/cask` API data files for <#{HOMEBREW_API_WWW}>.
|
||||
The generated files are written to the current directory.
|
||||
@ -20,28 +26,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
CASK_JSON_TEMPLATE = <<~EOS
|
||||
---
|
||||
layout: cask_json
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
|
||||
def html_template(title)
|
||||
<<~EOS
|
||||
---
|
||||
title: #{title}
|
||||
layout: cask
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
end
|
||||
|
||||
def generate_cask_api
|
||||
args = generate_cask_api_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
tap = CoreCaskTap.instance
|
||||
raise TapUnavailableError, tap.name unless tap.installed?
|
||||
|
||||
@ -79,4 +66,18 @@ module Homebrew
|
||||
File.write("api/internal/v3/homebrew-cask.json", homebrew_cask_tap_json) unless args.dry_run?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def html_template(title)
|
||||
<<~EOS
|
||||
---
|
||||
title: #{title}
|
||||
layout: cask
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -5,11 +5,16 @@ require "cli/parser"
|
||||
require "formula"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
module DevCmd
|
||||
class GenerateFormulaApi < AbstractCommand
|
||||
FORMULA_JSON_TEMPLATE = <<~EOS
|
||||
---
|
||||
layout: formula_json
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def generate_formula_api_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Generate `homebrew/core` API data files for <#{HOMEBREW_API_WWW}>.
|
||||
The generated files are written to the current directory.
|
||||
@ -19,29 +24,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
FORMULA_JSON_TEMPLATE = <<~EOS
|
||||
---
|
||||
layout: formula_json
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
|
||||
def html_template(title)
|
||||
<<~EOS
|
||||
---
|
||||
title: #{title}
|
||||
layout: formula
|
||||
redirect_from: /formula-linux/#{title}
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
end
|
||||
|
||||
def generate_formula_api
|
||||
args = generate_formula_api_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
tap = CoreTap.instance
|
||||
raise TapUnavailableError, tap.name unless tap.installed?
|
||||
|
||||
@ -80,4 +65,19 @@ module Homebrew
|
||||
File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def html_template(title)
|
||||
<<~EOS
|
||||
---
|
||||
title: #{title}
|
||||
layout: formula
|
||||
redirect_from: /formula-linux/#{title}
|
||||
---
|
||||
{{ content }}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,27 +1,26 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "completions"
|
||||
require "manpages"
|
||||
require "system_command"
|
||||
|
||||
module Homebrew
|
||||
extend SystemCommand::Mixin
|
||||
module DevCmd
|
||||
class GenerateManCompletions < AbstractCommand
|
||||
include SystemCommand::Mixin
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.generate_man_completions_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Generate Homebrew's manpages and shell completions.
|
||||
EOS
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_man_completions
|
||||
args = generate_man_completions_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
Commands.rebuild_internal_commands_completion_list
|
||||
Manpages.regenerate_man_pages(quiet: args.quiet?)
|
||||
Completions.update_shell_completions!
|
||||
@ -35,4 +34,6 @@ module Homebrew
|
||||
puts "Manpage and completions updated."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def install_bundler_gems_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class InstallBundlerGems < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Install Homebrew's Bundler gems.
|
||||
EOS
|
||||
@ -23,11 +22,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
def install_bundler_gems
|
||||
args = install_bundler_gems_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
groups = args.groups || args.add_groups || []
|
||||
|
||||
if groups.delete("all")
|
||||
@ -38,4 +35,6 @@ module Homebrew
|
||||
|
||||
Homebrew.install_bundler_gems!(groups:)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formulary"
|
||||
require "cask/cask_loader"
|
||||
require "cli/parser"
|
||||
@ -27,11 +28,9 @@ class Symbol
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def irb_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class Irb < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Enter the interactive Homebrew Ruby shell.
|
||||
EOS
|
||||
@ -41,12 +40,13 @@ module Homebrew
|
||||
env: :pry,
|
||||
description: "Use Pry instead of IRB. Implied if `HOMEBREW_PRY` is set."
|
||||
end
|
||||
end
|
||||
|
||||
def irb
|
||||
# work around IRB modifying ARGV.
|
||||
args = irb_args.parse(ARGV.dup.freeze)
|
||||
sig { params(argv: T.nilable(T::Array[String])).void }
|
||||
def initialize(argv = nil) = super(argv || ARGV.dup.freeze)
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
clean_argv
|
||||
|
||||
if args.examples?
|
||||
@ -88,6 +88,8 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Remove the `--debug`, `--verbose` and `--quiet` options which cause problems
|
||||
# for IRB and have already been parsed by the CLI::Parser.
|
||||
def clean_argv
|
||||
@ -96,4 +98,6 @@ module Homebrew
|
||||
.flat_map { |options| options[0..1] }
|
||||
ARGV.reject! { |arg| global_options.include?(arg) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cache_store"
|
||||
require "linkage_checker"
|
||||
require "cli/parser"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def linkage_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class Linkage < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Check the library links from the given <formula> kegs. If no <formula> are
|
||||
provided, check all kegs. Raises an error if run on uninstalled formulae.
|
||||
@ -30,11 +29,9 @@ module Homebrew
|
||||
|
||||
named_args :installed_formula
|
||||
end
|
||||
end
|
||||
|
||||
def linkage
|
||||
args = linkage_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
CacheStoreDatabase.use(:linkage) do |db|
|
||||
kegs = if args.named.to_default_kegs.empty?
|
||||
Formula.installed.filter_map(&:any_installed_keg)
|
||||
@ -57,4 +54,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "formula"
|
||||
require "livecheck/livecheck"
|
||||
require "livecheck/strategy"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def livecheck_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class LivecheckCmd < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Check for newer versions of formulae and/or casks from upstream.
|
||||
If no formula or cask argument is passed, the list of formulae and
|
||||
@ -48,27 +47,9 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :cask], without_api: true
|
||||
end
|
||||
end
|
||||
|
||||
def watchlist_path
|
||||
@watchlist_path ||= begin
|
||||
watchlist = File.expand_path(Homebrew::EnvConfig.livecheck_watchlist)
|
||||
|
||||
unless File.exist?(watchlist)
|
||||
previous_default_watchlist = File.expand_path("~/.brew_livecheck_watchlist")
|
||||
if File.exist?(previous_default_watchlist)
|
||||
odisabled "~/.brew_livecheck_watchlist", "~/.homebrew/livecheck_watchlist.txt"
|
||||
watchlist = previous_default_watchlist
|
||||
end
|
||||
end
|
||||
|
||||
watchlist
|
||||
end
|
||||
end
|
||||
|
||||
def livecheck
|
||||
args = livecheck_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
Homebrew.install_bundler_gems!(groups: ["livecheck"])
|
||||
|
||||
all = args.eval_all?
|
||||
@ -80,7 +61,7 @@ module Homebrew
|
||||
|
||||
formulae_and_casks_to_check = Homebrew.with_no_api_env do
|
||||
if args.tap
|
||||
tap = Tap.fetch(args.tap)
|
||||
tap = Tap.fetch(T.must(args.tap))
|
||||
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
|
||||
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
|
||||
formulae + casks
|
||||
@ -136,4 +117,24 @@ module Homebrew
|
||||
|
||||
Livecheck.run_checks(formulae_and_casks_to_check, **options)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def watchlist_path
|
||||
@watchlist_path ||= begin
|
||||
watchlist = File.expand_path(Homebrew::EnvConfig.livecheck_watchlist)
|
||||
|
||||
unless File.exist?(watchlist)
|
||||
previous_default_watchlist = File.expand_path("~/.brew_livecheck_watchlist")
|
||||
if File.exist?(previous_default_watchlist)
|
||||
odisabled "~/.brew_livecheck_watchlist", "~/.homebrew/livecheck_watchlist.txt"
|
||||
watchlist = previous_default_watchlist
|
||||
end
|
||||
end
|
||||
|
||||
watchlist
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "utils/github"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def pr_automerge_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class PrAutomerge < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Find pull requests that can be automatically merged using `brew pr-publish`.
|
||||
EOS
|
||||
@ -40,11 +39,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
def pr_automerge
|
||||
args = pr_automerge_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
without_labels = args.without_labels || [
|
||||
"do not merge",
|
||||
"new formula",
|
||||
@ -58,7 +55,7 @@ module Homebrew
|
||||
query += args.ignore_failures? ? " -status:pending" : " status:success"
|
||||
query += " review:approved" unless args.without_approval?
|
||||
query += " label:\"#{args.with_label}\"" if args.with_label
|
||||
without_labels&.each { |label| query += " -label:\"#{label}\"" }
|
||||
without_labels.each { |label| query += " -label:\"#{label}\"" }
|
||||
odebug "Searching: #{query}"
|
||||
|
||||
prs = GitHub.search_issues query
|
||||
@ -84,4 +81,6 @@ module Homebrew
|
||||
ohai "Now run:", " brew #{publish_args.join " "} \\\n #{pr_urls.join " \\\n "}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "utils/github"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def pr_publish_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class PrPublish < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Publish bottles for a pull request with GitHub Actions.
|
||||
Requires write access to the repository.
|
||||
@ -31,11 +30,9 @@ module Homebrew
|
||||
|
||||
named_args :pull_request, min: 1
|
||||
end
|
||||
end
|
||||
|
||||
def pr_publish
|
||||
args = pr_publish_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
tap = Tap.fetch(args.tap || CoreTap.instance.name)
|
||||
workflow = args.workflow || "publish-commit-bottles.yml"
|
||||
ref = args.branch || "master"
|
||||
@ -72,4 +69,6 @@ module Homebrew
|
||||
GitHub.workflow_dispatch_event(user, repo, workflow, ref, **inputs)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -39,6 +39,11 @@ RSpec.describe Homebrew::AbstractCommand do
|
||||
expect(described_class.command("test-cat")).to be(TestCat)
|
||||
end
|
||||
|
||||
it "removes -cmd suffix from command name" do
|
||||
require "dev-cmd/formula"
|
||||
expect(Homebrew::DevCmd::FormulaCmd.command_name).to eq("formula")
|
||||
end
|
||||
|
||||
describe "when command name is overridden" do
|
||||
before do
|
||||
tac = Class.new(described_class) do
|
||||
@ -61,7 +66,7 @@ RSpec.describe Homebrew::AbstractCommand do
|
||||
["cmd", "dev-cmd"].each do |dir|
|
||||
Dir[File.join(__dir__, "../#{dir}", "*.rb")].each { require(_1) }
|
||||
end
|
||||
test_classes = ["Cat", "Tac"]
|
||||
test_classes = ["TestCat", "Tac"]
|
||||
|
||||
described_class.subclasses.each do |klass|
|
||||
next if test_classes.include?(klass.name)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.shared_examples "parseable arguments" do |argv: []|
|
||||
RSpec.shared_examples "parseable arguments" do |argv: nil|
|
||||
subject(:method_name) { "#{command_name.tr("-", "_")}_args" }
|
||||
|
||||
let(:command_name) do |example|
|
||||
@ -9,6 +9,8 @@ RSpec.shared_examples "parseable arguments" do |argv: []|
|
||||
|
||||
it "can parse arguments" do
|
||||
if described_class
|
||||
argv ||= described_class.parser.instance_variable_get(:@min_named_args)&.times&.map { "argument" }
|
||||
argv ||= []
|
||||
cmd = described_class.new(argv)
|
||||
expect(cmd.args).to be_a Homebrew::CLI::Args
|
||||
else
|
||||
|
||||
@ -30,7 +30,7 @@ RSpec.describe Homebrew::DevCmd::Bottle do
|
||||
EOS
|
||||
end
|
||||
|
||||
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "builds a bottle for the given Formula", :integration_test do
|
||||
install_test_formula "testball", build_bottle: true
|
||||
|
||||
@ -4,5 +4,5 @@ require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/bump-cask-pr"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::BumpCaskPr do
|
||||
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -4,5 +4,5 @@ require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/bump-revision"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::BumpRevision do
|
||||
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -4,5 +4,5 @@ require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/bump-unversioned-casks"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::BumpUnversionedCasks do
|
||||
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -4,7 +4,7 @@ require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/cat"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::Cat do
|
||||
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "prints the content of a given Formula", :integration_test do
|
||||
formula_file = setup_test_formula "testball"
|
||||
|
||||
@ -4,7 +4,7 @@ require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/command"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::Command do
|
||||
it_behaves_like "parseable arguments", argv: ["foo"]
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "returns the file for a given command", :integration_test do
|
||||
expect { brew "command", "info" }
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/create"
|
||||
|
||||
RSpec.describe "brew create" do
|
||||
RSpec.describe Homebrew::DevCmd::Create do
|
||||
let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
|
||||
let(:formula_file) { CoreTap.instance.new_formula_path("testball") }
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
require "dev-cmd/determine-test-runners"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe "brew determine-test-runners" do
|
||||
RSpec.describe Homebrew::DevCmd::DetermineTestRunners do
|
||||
def get_runners(file)
|
||||
runner_line = File.open(file).first
|
||||
json_text = runner_line[/runners=(.*)/, 1]
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/dispatch-build-bottle"
|
||||
|
||||
RSpec.describe "brew dispatch-build-bottle" do
|
||||
RSpec.describe Homebrew::DevCmd::DispatchBuildBottle do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/edit"
|
||||
|
||||
RSpec.describe "brew edit" do
|
||||
RSpec.describe Homebrew::DevCmd::Edit do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "opens a given Formula in an editor", :integration_test do
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/extract"
|
||||
|
||||
RSpec.describe "brew extract" do
|
||||
RSpec.describe Homebrew::DevCmd::Extract do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
context "when extracting a formula" do
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/formula"
|
||||
|
||||
RSpec.describe "brew formula" do
|
||||
RSpec.describe Homebrew::DevCmd::FormulaCmd do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "prints a given Formula's path", :integration_test do
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/generate-cask-api"
|
||||
|
||||
RSpec.describe "brew generate-cask-api" do
|
||||
RSpec.describe Homebrew::DevCmd::GenerateCaskApi do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/generate-formula-api"
|
||||
|
||||
RSpec.describe "brew generate-formula-api" do
|
||||
RSpec.describe Homebrew::DevCmd::GenerateFormulaApi do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/generate-man-completions"
|
||||
|
||||
RSpec.describe "brew generate-man-completions" do
|
||||
RSpec.describe Homebrew::DevCmd::GenerateManCompletions do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/install-bundler-gems"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::InstallBundlerGems do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/irb"
|
||||
|
||||
RSpec.describe "brew irb" do
|
||||
RSpec.describe Homebrew::DevCmd::Irb do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
describe "integration test" do
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/linkage"
|
||||
|
||||
RSpec.describe "brew linkage" do
|
||||
RSpec.describe Homebrew::DevCmd::Linkage do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "works when no arguments are provided", :integration_test do
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/livecheck"
|
||||
|
||||
RSpec.describe "brew livecheck" do
|
||||
RSpec.describe Homebrew::DevCmd::LivecheckCmd do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "reports the latest version of a Formula", :integration_test, :needs_network do
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/pr-automerge"
|
||||
|
||||
RSpec.describe "brew pr-automerge" do
|
||||
RSpec.describe Homebrew::DevCmd::PrAutomerge do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/pr-publish"
|
||||
|
||||
RSpec.describe "brew pr-publish" do
|
||||
RSpec.describe Homebrew::DevCmd::PrPublish do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user