Class: Homebrew::CLI::Args Private

Inherits:
Object show all
Defined in:
cli/args.rbi,
cli/args.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

This file contains global args as defined in Homebrew::CLI::Parser.global_options Command-specific args are defined in the commands themselves, with type signatures generated by the Tapioca::Compilers::Args compiler.

Direct Known Subclasses

Homebrew::Cmd::Alias::Args, Homebrew::Cmd::Analytics::Args, Homebrew::Cmd::AsBrewUser::Args, Homebrew::Cmd::AsConsoleUser::Args, Homebrew::Cmd::Autoremove::Args, Homebrew::Cmd::Bundle::Args, Homebrew::Cmd::Cache::Args, Homebrew::Cmd::Caskroom::Args, Homebrew::Cmd::Casks::Args, Homebrew::Cmd::Cellar::Args, Homebrew::Cmd::CleanupCmd::Args, Homebrew::Cmd::Command::Args, Homebrew::Cmd::CommandNotFoundInit::Args, Homebrew::Cmd::CommandsCmd::Args, Homebrew::Cmd::CompletionsCmd::Args, Homebrew::Cmd::Config::Args, Homebrew::Cmd::Deps::Args, Homebrew::Cmd::Desc::Args, Homebrew::Cmd::Developer::Args, Homebrew::Cmd::Docs::Args, Homebrew::Cmd::Doctor::Args, Homebrew::Cmd::Env::Args, Homebrew::Cmd::Exec::Args, Homebrew::Cmd::FetchCmd::Args, Homebrew::Cmd::Formulae::Args, Homebrew::Cmd::GistLogs::Args, Homebrew::Cmd::HelpCmd::Args, Homebrew::Cmd::Home::Args, Homebrew::Cmd::Info::Args, Homebrew::Cmd::InstallCmd::Args, Homebrew::Cmd::Leaves::Args, Homebrew::Cmd::Link::Args, Homebrew::Cmd::List::Args, Homebrew::Cmd::Log::Args, Homebrew::Cmd::McpServerCmd::Args, Homebrew::Cmd::Migrate::Args, Homebrew::Cmd::Missing::Args, Homebrew::Cmd::NodenvSync::Args, Homebrew::Cmd::OptionsCmd::Args, Homebrew::Cmd::Outdated::Args, Homebrew::Cmd::Pin::Args, Homebrew::Cmd::Postinstall::Args, Homebrew::Cmd::Prefix::Args, Homebrew::Cmd::PyenvSync::Args, Homebrew::Cmd::RbenvSync::Args, Homebrew::Cmd::ReadallCmd::Args, Homebrew::Cmd::Reinstall::Args, Homebrew::Cmd::Repository::Args, Homebrew::Cmd::SandboxExec::Args, Homebrew::Cmd::SearchCmd::Args, Homebrew::Cmd::Services::Args, Homebrew::Cmd::SetupRuby::Args, Homebrew::Cmd::Shellenv::Args, Homebrew::Cmd::Source::Args, Homebrew::Cmd::TabCmd::Args, Homebrew::Cmd::TapCmd::Args, Homebrew::Cmd::TapInfo::Args, Homebrew::Cmd::Taps::Args, Homebrew::Cmd::TestBotCmd::Args, Homebrew::Cmd::Trust::Args, Homebrew::Cmd::Unalias::Args, Homebrew::Cmd::UninstallCmd::Args, Homebrew::Cmd::UnlinkCmd::Args, Homebrew::Cmd::Unpin::Args, Homebrew::Cmd::Untap::Args, Homebrew::Cmd::Untrust::Args, Homebrew::Cmd::Update::Args, Homebrew::Cmd::UpdateIfNeeded::Args, Homebrew::Cmd::UpdateReport::Args, Homebrew::Cmd::UpdateReset::Args, Homebrew::Cmd::UpgradeCmd::Args, Homebrew::Cmd::Uses::Args, Homebrew::Cmd::VendorInstall::Args, Homebrew::Cmd::Version::Args, Homebrew::Cmd::VersionInstall::Args, Homebrew::Cmd::Vulns::Args, Homebrew::Cmd::WhichFormula::Args, DevCmd::AdvisoryMatch::Args, DevCmd::Audit::Args, DevCmd::Benchmark::Args, DevCmd::Bottle::Args, DevCmd::Bump::Args, DevCmd::BumpCaskPr::Args, DevCmd::BumpCompatibilityVersion::Args, DevCmd::BumpFormulaPr::Args, DevCmd::BumpPythonResourcesPr::Args, DevCmd::BumpRevision::Args, DevCmd::BumpUnversionedCasks::Args, DevCmd::CaskCi::Args, DevCmd::Cat::Args, DevCmd::Contributions::Args, DevCmd::Create::Args, DevCmd::Debugger::Args, DevCmd::DetermineTestRunners::Args, DevCmd::DispatchBuildBottle::Args, DevCmd::Edit::Args, DevCmd::Extract::Args, DevCmd::FindAppcast::Args, DevCmd::FormulaAnalytics::Args, DevCmd::FormulaCmd::Args, DevCmd::FormulaPythonResources::Args, DevCmd::GenerateAdvisoriesApi::Args, DevCmd::GenerateAnalyticsApi::Args, DevCmd::GenerateBottleCiMatrix::Args, DevCmd::GenerateCaskApi::Args, DevCmd::GenerateCaskCiMatrix::Args, DevCmd::GenerateCaskFeeds::Args, DevCmd::GenerateCaskToken::Args, DevCmd::GenerateFormulaApi::Args, DevCmd::GenerateFormulaFeeds::Args, DevCmd::GenerateInternalApi::Args, DevCmd::GenerateManCompletions::Args, DevCmd::GenerateVulnsAdvisories::Args, DevCmd::GenerateZap::Args, DevCmd::InstallBundlerGems::Args, DevCmd::Irb::Args, DevCmd::Lgtm::Args, DevCmd::Linkage::Args, DevCmd::LivecheckCmd::Args, DevCmd::PrAutomerge::Args, DevCmd::PrPublish::Args, DevCmd::PrPull::Args, DevCmd::PrUpload::Args, DevCmd::Prof::Args, DevCmd::Release::Args, DevCmd::Rubocop::Args, DevCmd::Ruby::Args, DevCmd::Rubydoc::Args, DevCmd::Sh::Args, DevCmd::StyleCmd::Args, DevCmd::TapNew::Args, DevCmd::Test::Args, DevCmd::Tests::Args, DevCmd::Typecheck::Args, DevCmd::Unbottled::Args, DevCmd::Unpack::Args, DevCmd::UpdateLicenseData::Args, DevCmd::UpdateMaintainers::Args, DevCmd::UpdatePerlResources::Args, DevCmd::UpdatePortableRuby::Args, DevCmd::UpdatePythonResources::Args, DevCmd::UpdateSponsors::Args, DevCmd::UpdateTest::Args, DevCmd::VendorGems::Args, DevCmd::Verify::Args, DevCmd::WhichUpdate::Args

Constant Summary collapse

OptionsType =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

Represents a processed option. The array elements are:

0: short option name (e.g. "-d")
1: long option name (e.g. "--debug")
2: option description (e.g. "Print debugging information")
3: whether the option is hidden
T.type_alias { T::Array[[T.nilable(String), T.nilable(String), String, T::Boolean]] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'cli/args.rb', line 18

def initialize
  require "cli/named_args"

  @cli_args = T.let(nil, T.nilable(T::Array[String]))
  @processed_options = T.let([], OptionsType)
  @env_options = T.let([], T::Array[String])
  @options_only = T.let([], T::Array[String])
  @flags_only = T.let([], T::Array[String])
  @cask_options = T.let(false, T::Boolean)
  @table = T.let({}, T::Hash[Symbol, T.untyped])

  # Can set these because they will be overwritten by freeze_named_args!
  # (whereas other values below will only be overwritten if passed).
  @named = T.let(NamedArgs.new(parent: self), NamedArgs)
  @remaining = T.let([], T::Array[String])
end

Instance Attribute Details

#flags_only ⇒ Array<String> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



15
16
17
# File 'cli/args.rb', line 15

def flags_only
  @flags_only
end

#options_only ⇒ Array<String> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



15
16
17
# File 'cli/args.rb', line 15

def options_only
  @options_only
end

#remaining ⇒ Array<String> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



15
16
17
# File 'cli/args.rb', line 15

def remaining
  @remaining
end

Instance Method Details

#build_from_source_formulae ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



91
92
93
94
95
96
97
# File 'cli/args.rb', line 91

def build_from_source_formulae
  if @table[:build_from_source?] || @table[:HEAD?] || @table[:build_bottle?]
    named.to_formulae.map(&:full_name)
  else
    []
  end
end

#cask_require_sha? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


86
87
88
# File 'cli/args.rb', line 86

def cask_require_sha?
  !!(@table[:require_sha?] == true && (@table[:force?] != true || @env_options.exclude?("require_sha")))
end

#context ⇒ Context::ContextStruct

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



118
119
120
# File 'cli/args.rb', line 118

def context
  Context::ContextStruct.new(debug: debug?, quiet: quiet?, verbose: verbose?)
end

#debug? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


9
# File 'cli/args.rbi', line 9

def debug?; end

#freeze_named_args!(named_args, cask_options:, without_api:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • named_args (Array<String>)
  • cask_options (Boolean)
  • without_api (Boolean)


39
40
41
42
43
44
45
46
47
48
49
# File 'cli/args.rb', line 39

def freeze_named_args!(named_args, cask_options:, without_api:)
  @named = NamedArgs.new(
    *named_args.freeze,
    cask_options:,
    flags:         flags_only,
    force_bottle:  @table[:force_bottle?] || false,
    override_spec: @table[:HEAD?] ? :head : nil,
    parent:        self,
    without_api:,
  )
end

#freeze_processed_options!(processed_options, env_options: []) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



64
65
66
67
68
69
70
71
72
73
74
# File 'cli/args.rb', line 64

def freeze_processed_options!(processed_options, env_options: [])
  # Reset cache values reliant on processed_options
  @cli_args = nil

  @processed_options += processed_options
  @processed_options.freeze
  @env_options = env_options.freeze

  @options_only = cli_args.select { it.start_with?("-") }.freeze
  @flags_only = cli_args.select { it.start_with?("--") }.freeze
end

#freeze_remaining_args!(remaining_args) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



36
# File 'cli/args.rb', line 36

def freeze_remaining_args!(remaining_args) = @remaining.replace(remaining_args).freeze

#help? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


12
# File 'cli/args.rbi', line 12

def help?; end

#include_test_formulae ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



100
101
102
103
104
105
106
# File 'cli/args.rb', line 100

def include_test_formulae
  if @table[:include_test?]
    named.to_formulae.map(&:full_name)
  else
    []
  end
end

#named ⇒ NamedArgs

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



77
78
79
80
# File 'cli/args.rb', line 77

def named
  require "formula"
  @named
end

#no_named? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


83
# File 'cli/args.rb', line 83

def no_named? = named.empty?

#only_formula_or_cask ⇒ Symbol?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



123
124
125
126
127
128
129
# File 'cli/args.rb', line 123

def only_formula_or_cask
  if @table[:formula?] && !@table[:cask?]
    :formula
  elsif @table[:cask?] && !@table[:formula?]
    :cask
  end
end

#os_arch_combinations(allow_all: true) ⇒ Array<Array<(Symbol, Symbol)>>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • allow_all (Boolean) (defaults to: true)

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'cli/args.rb', line 132

def os_arch_combinations(allow_all: true)
  # `--all-platforms` is equivalent to `--os=all --arch=all`.
  all_platforms = @table[:all_platforms?]

  os_sym = all_platforms ? :all : @table[:os]&.to_sym
  oses = if os_sym.nil?
    [SimulateSystem.current_os]
  elsif os_sym == :all && allow_all
    OnSystem::ALL_OS_OPTIONS
  elsif os_sym == :macos || OnSystem::ALL_OS_OPTIONS.include?(os_sym)
    [os_sym]
  else
    os_choices = OnSystem::BASE_OS_OPTIONS.dup
    os_choices << :all if allow_all
    raise UsageError, "`--os` does not accept #{os_sym.to_s.inspect}.\n" \
                      "Use #{os_choices.join(", ")} or one of the following macOS versions.\n  " \
                      "#{MacOSVersion::SYMBOLS.keys.join(", ")}"
  end

  arch_sym = all_platforms ? :all : @table[:arch]&.to_sym
  arches = if arch_sym.nil?
    [SimulateSystem.current_arch]
  elsif arch_sym == :all && allow_all
    OnSystem::ARCH_OPTIONS
  elsif OnSystem::ARCH_OPTIONS.include?(arch_sym)
    [arch_sym]
  else
    arch_choices = OnSystem::ARCH_OPTIONS.sort
    arch_choices << :all if allow_all
    raise UsageError, "`--arch` does not accept #{arch_sym.to_s.inspect}.\n" \
                      "Use #{Utils::Text.to_sentence(arch_choices, conjunction: "or")}."
  end

  oses.product(arches)
end

#quiet? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


15
# File 'cli/args.rbi', line 15

def quiet?; end

#set_arg(name, value) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



52
53
54
# File 'cli/args.rb', line 52

def set_arg(name, value)
  @table[name] = value
end

#tap(&_blk) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • _blk (T.proc.params(x: T.untyped).void, nil)

Returns:

  • (T.untyped)


57
58
59
60
61
# File 'cli/args.rb', line 57

def tap(&_blk)
  return super if block_given? # Object#tap

  @table[:tap]
end

#value(name) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



109
110
111
112
113
114
115
# File 'cli/args.rb', line 109

def value(name)
  arg_prefix = "--#{name}="
  flag_with_value = flags_only.find { |arg| arg.start_with?(arg_prefix) }
  return unless flag_with_value

  flag_with_value.delete_prefix(arg_prefix)
end

#verbose? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


18
# File 'cli/args.rbi', line 18

def verbose?; end