Add without_api specifier for CLI named args
This commit is contained in:
parent
1c081f379d
commit
68289f1165
@ -176,4 +176,20 @@ module Homebrew
|
|||||||
Tap.fetch(org, repo)
|
Tap.fetch(org, repo)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @api private
|
||||||
|
sig { params(block: T.proc.returns(T.untyped)).returns(T.untyped) }
|
||||||
|
def self.with_no_api_env(&block)
|
||||||
|
return yield if Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
|
||||||
|
with_env(HOMEBREW_NO_INSTALL_FROM_API: "1", HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API: "1", &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
# @api private
|
||||||
|
sig { params(condition: T::Boolean, block: T.proc.returns(T.untyped)).returns(T.untyped) }
|
||||||
|
def self.with_no_api_env_if_needed(condition, &block)
|
||||||
|
return yield unless condition
|
||||||
|
|
||||||
|
with_no_api_env(&block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ module Homebrew
|
|||||||
self[:remaining] = remaining_args.freeze
|
self[:remaining] = remaining_args.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def freeze_named_args!(named_args, cask_options:)
|
def freeze_named_args!(named_args, cask_options:, without_api:)
|
||||||
options = {}
|
options = {}
|
||||||
options[:force_bottle] = true if self[:force_bottle?]
|
options[:force_bottle] = true if self[:force_bottle?]
|
||||||
options[:override_spec] = :head if self[:HEAD?]
|
options[:override_spec] = :head if self[:HEAD?]
|
||||||
@ -41,6 +41,7 @@ module Homebrew
|
|||||||
*named_args.freeze,
|
*named_args.freeze,
|
||||||
parent: self,
|
parent: self,
|
||||||
cask_options: cask_options,
|
cask_options: cask_options,
|
||||||
|
without_api: without_api,
|
||||||
**options,
|
**options,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,7 @@ module Homebrew
|
|||||||
force_bottle: T::Boolean,
|
force_bottle: T::Boolean,
|
||||||
flags: T::Array[String],
|
flags: T::Array[String],
|
||||||
cask_options: T::Boolean,
|
cask_options: T::Boolean,
|
||||||
|
without_api: T::Boolean,
|
||||||
).void
|
).void
|
||||||
}
|
}
|
||||||
def initialize(
|
def initialize(
|
||||||
@ -27,7 +28,8 @@ module Homebrew
|
|||||||
override_spec: T.unsafe(nil),
|
override_spec: T.unsafe(nil),
|
||||||
force_bottle: T.unsafe(nil),
|
force_bottle: T.unsafe(nil),
|
||||||
flags: T.unsafe(nil),
|
flags: T.unsafe(nil),
|
||||||
cask_options: false
|
cask_options: false,
|
||||||
|
without_api: false
|
||||||
)
|
)
|
||||||
require "cask/cask"
|
require "cask/cask"
|
||||||
require "cask/cask_loader"
|
require "cask/cask_loader"
|
||||||
@ -40,6 +42,7 @@ module Homebrew
|
|||||||
@force_bottle = force_bottle
|
@force_bottle = force_bottle
|
||||||
@flags = flags
|
@flags = flags
|
||||||
@cask_options = cask_options
|
@cask_options = cask_options
|
||||||
|
@without_api = without_api
|
||||||
@parent = parent
|
@parent = parent
|
||||||
|
|
||||||
super(@args)
|
super(@args)
|
||||||
@ -112,6 +115,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_formula_or_cask(name, only: nil, method: nil, warn: nil)
|
def load_formula_or_cask(name, only: nil, method: nil, warn: nil)
|
||||||
|
Homebrew.with_no_api_env_if_needed(@without_api) do
|
||||||
unreadable_error = nil
|
unreadable_error = nil
|
||||||
|
|
||||||
if only != :cask
|
if only != :cask
|
||||||
@ -199,6 +203,7 @@ module Homebrew
|
|||||||
|
|
||||||
raise FormulaOrCaskUnavailableError, name
|
raise FormulaOrCaskUnavailableError, name
|
||||||
end
|
end
|
||||||
|
end
|
||||||
private :load_formula_or_cask
|
private :load_formula_or_cask
|
||||||
|
|
||||||
def resolve_formula(name)
|
def resolve_formula(name)
|
||||||
|
@ -138,6 +138,7 @@ module Homebrew
|
|||||||
@named_args_type = nil
|
@named_args_type = nil
|
||||||
@max_named_args = nil
|
@max_named_args = nil
|
||||||
@min_named_args = nil
|
@min_named_args = nil
|
||||||
|
@named_args_without_api = false
|
||||||
@description = nil
|
@description = nil
|
||||||
@usage_banner = nil
|
@usage_banner = nil
|
||||||
@hide_from_man_page = false
|
@hide_from_man_page = false
|
||||||
@ -346,7 +347,7 @@ module Homebrew
|
|||||||
check_named_args(named_args)
|
check_named_args(named_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
@args.freeze_named_args!(named_args, cask_options: @cask_options)
|
@args.freeze_named_args!(named_args, cask_options: @cask_options, without_api: @named_args_without_api)
|
||||||
@args.freeze_remaining_args!(non_options.empty? ? remaining : [*remaining, "--", non_options])
|
@args.freeze_remaining_args!(non_options.empty? ? remaining : [*remaining, "--", non_options])
|
||||||
@args.freeze_processed_options!(@processed_options)
|
@args.freeze_processed_options!(@processed_options)
|
||||||
@args.freeze
|
@args.freeze
|
||||||
@ -396,9 +397,10 @@ module Homebrew
|
|||||||
number: T.nilable(Integer),
|
number: T.nilable(Integer),
|
||||||
min: T.nilable(Integer),
|
min: T.nilable(Integer),
|
||||||
max: T.nilable(Integer),
|
max: T.nilable(Integer),
|
||||||
|
without_api: T::Boolean,
|
||||||
).void
|
).void
|
||||||
}
|
}
|
||||||
def named_args(type = nil, number: nil, min: nil, max: nil)
|
def named_args(type = nil, number: nil, min: nil, max: nil, without_api: false)
|
||||||
if number.present? && (min.present? || max.present?)
|
if number.present? && (min.present? || max.present?)
|
||||||
raise ArgumentError, "Do not specify both `number` and `min` or `max`"
|
raise ArgumentError, "Do not specify both `number` and `min` or `max`"
|
||||||
end
|
end
|
||||||
@ -417,6 +419,8 @@ module Homebrew
|
|||||||
@min_named_args = min
|
@min_named_args = min
|
||||||
@max_named_args = max
|
@max_named_args = max
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@named_args_without_api = without_api
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
|
@ -123,7 +123,7 @@ module Homebrew
|
|||||||
ENV.activate_extensions!
|
ENV.activate_extensions!
|
||||||
ENV.setup_build_environment
|
ENV.setup_build_environment
|
||||||
|
|
||||||
audit_formulae, audit_casks = without_api do # audit requires full Ruby source
|
audit_formulae, audit_casks = with_no_api_env do # audit requires full Ruby source
|
||||||
if args.tap
|
if args.tap
|
||||||
Tap.fetch(args.tap).then do |tap|
|
Tap.fetch(args.tap).then do |tap|
|
||||||
[
|
[
|
||||||
@ -217,7 +217,7 @@ module Homebrew
|
|||||||
# Audit requires full Ruby source so disable API.
|
# Audit requires full Ruby source so disable API.
|
||||||
# We shouldn't do this for taps however so that we don't unnecessarily require a full Homebrew/core clone.
|
# We shouldn't do this for taps however so that we don't unnecessarily require a full Homebrew/core clone.
|
||||||
fa = if f.core_formula?
|
fa = if f.core_formula?
|
||||||
without_api(&audit_proc)
|
with_no_api_env(&audit_proc)
|
||||||
else
|
else
|
||||||
audit_proc.call
|
audit_proc.call
|
||||||
end
|
end
|
||||||
@ -347,10 +347,4 @@ module Homebrew
|
|||||||
"* #{location}#{message.chomp.gsub("\n", "\n ")}#{status}"
|
"* #{location}#{message.chomp.gsub("\n", "\n ")}#{status}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.without_api(&block)
|
|
||||||
return yield if Homebrew::EnvConfig.no_install_from_api?
|
|
||||||
|
|
||||||
with_env(HOMEBREW_NO_INSTALL_FROM_API: "1", HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API: "1", &block)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -87,13 +87,19 @@ class FormulaOrCaskUnavailableError < RuntimeError
|
|||||||
super()
|
super()
|
||||||
|
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
|
# Store the state of these envs at the time the exception is thrown.
|
||||||
|
# This is so we do the fuzzy search for "did you mean" etc under that same mode,
|
||||||
|
# in case the list of formulae are different.
|
||||||
|
@without_api = Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
@auto_without_api = Homebrew::EnvConfig.automatically_set_no_install_from_api?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def did_you_mean
|
def did_you_mean
|
||||||
require "formula"
|
require "formula"
|
||||||
|
|
||||||
similar_formula_names = Formula.fuzzy_search(name)
|
similar_formula_names = Homebrew.with_no_api_env_if_needed(@without_api) { Formula.fuzzy_search(name) }
|
||||||
return "" if similar_formula_names.blank?
|
return "" if similar_formula_names.blank?
|
||||||
|
|
||||||
"Did you mean #{similar_formula_names.to_sentence two_words_connector: " or ", last_word_connector: " or "}?"
|
"Did you mean #{similar_formula_names.to_sentence two_words_connector: " or ", last_word_connector: " or "}?"
|
||||||
@ -101,7 +107,11 @@ class FormulaOrCaskUnavailableError < RuntimeError
|
|||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def to_s
|
def to_s
|
||||||
"No available formula or cask with the name \"#{name}\". #{did_you_mean}".strip
|
s = "No available formula or cask with the name \"#{name}\". #{did_you_mean}".strip
|
||||||
|
if @auto_without_api && !CoreTap.instance.installed?
|
||||||
|
s += "\nA full git tap clone is required to use this command on core packages."
|
||||||
|
end
|
||||||
|
s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user