Class: Homebrew::CLI::Args Private

Inherits:
OpenStruct
  • 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::Analytics::Args, Homebrew::Cmd::Autoremove::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::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::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::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::SearchCmd::Args, Homebrew::Cmd::SetupRuby::Args, Homebrew::Cmd::Shellenv::Args, Homebrew::Cmd::TabCmd::Args, Homebrew::Cmd::TapCmd::Args, Homebrew::Cmd::TapInfo::Args, Homebrew::Cmd::UninstallCmd::Args, Homebrew::Cmd::UnlinkCmd::Args, Homebrew::Cmd::Unpin::Args, Homebrew::Cmd::Untap::Args, Homebrew::Cmd::Update::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, DevCmd::Audit::Args, DevCmd::Bottle::Args, DevCmd::Bump::Args, DevCmd::BumpCaskPr::Args, DevCmd::BumpFormulaPr::Args, DevCmd::BumpRevision::Args, DevCmd::BumpUnversionedCasks::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::FormulaCmd::Args, DevCmd::GenerateCaskApi::Args, DevCmd::GenerateCaskCiMatrix::Args, DevCmd::GenerateFormulaApi::Args, DevCmd::GenerateManCompletions::Args, DevCmd::InstallBundlerGems::Args, DevCmd::Irb::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::UpdatePythonResources::Args, DevCmd::UpdateSponsors::Args, DevCmd::UpdateTest::Args, DevCmd::VendorGems::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[[String, T.nilable(String), String, T::Boolean]] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid

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.



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

def initialize
  require "cli/named_args"

  super

  @cli_args = T.let(nil, T.nilable(T::Array[String]))
  @processed_options = T.let([], OptionsType)
  @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).
  self[:named] = NamedArgs.new(parent: self)
  self[:remaining] = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ T.untyped (private)

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:

  • method_name (Symbol)
  • args (T.untyped)

Returns:

  • (T.untyped)


188
189
190
191
192
193
194
195
196
197
198
# File 'cli/args.rb', line 188

def method_missing(method_name, *args)
  return_value = super

  # Once we are frozen, verify any arg method calls are already defined in the table.
  # The default OpenStruct behaviour is to return nil for anything unknown.
  if frozen? && args.empty? && !@table.key?(method_name)
    raise NoMethodError, "CLI arg for `#{method_name}` is not declared for this command"
  end

  return_value
end

Instance Attribute Details

#flags_onlyArray<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:



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

def flags_only
  @flags_only
end

#options_onlyArray<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:



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

def options_only
  @options_only
end

Instance Method Details

#archString?

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.

TODO:

The methods below are not defined by Args, but are valid because Args inherits from OpenStruct

We should instead be using type guards to check if the method is defined on the object before calling it

Returns:



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

def arch; end

#build_from_source?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)


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

def build_from_source?; end

#build_from_source_formulaeArray<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:



79
80
81
82
83
84
85
# File 'cli/args.rb', line 79

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

#cask?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)


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

def cask?; end

#contextContext::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.



106
107
108
# File 'cli/args.rb', line 106

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

#formula?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)


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

def formula?; 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)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'cli/args.rb', line 43

def freeze_named_args!(named_args, cask_options:, without_api:)
  options = {}
  options[:force_bottle] = true if self[:force_bottle?]
  options[:override_spec] = :head if self[:HEAD?]
  options[:flags] = flags_only unless flags_only.empty?
  self[:named] = NamedArgs.new(
    *named_args.freeze,
    parent:       self,
    cask_options:,
    without_api:,
    **options,
  )
end

#freeze_processed_options!(processed_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:



58
59
60
61
62
63
64
65
66
67
# File 'cli/args.rb', line 58

def freeze_processed_options!(processed_options)
  # Reset cache values reliant on processed_options
  @cli_args = nil

  @processed_options += processed_options
  @processed_options.freeze

  @options_only = cli_args.select { _1.start_with?("-") }.freeze
  @flags_only = cli_args.select { _1.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:



38
39
40
# File 'cli/args.rb', line 38

def freeze_remaining_args!(remaining_args)
  self[:remaining] = remaining_args.freeze
end

#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?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)


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

def include_test?; end

#include_test_formulaeArray<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:



88
89
90
91
92
93
94
# File 'cli/args.rb', line 88

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

#namedNamedArgs

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:



70
71
72
73
# File 'cli/args.rb', line 70

def named
  require "formula"
  self[: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)


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

def no_named? = named.blank?

#only_formula_or_caskSymbol?

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:



111
112
113
114
115
116
117
# File 'cli/args.rb', line 111

def only_formula_or_cask
  if formula? && !cask?
    :formula
  elsif cask? && !formula?
    :cask
  end
end

#osString?

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:



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

def os; end

#os_arch_combinationsArray<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.

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'cli/args.rb', line 120

def os_arch_combinations
  skip_invalid_combinations = false

  oses = case (os_sym = os&.to_sym)
  when nil
    [SimulateSystem.current_os]
  when :all
    skip_invalid_combinations = true

    OnSystem::ALL_OS_OPTIONS
  else
    [os_sym]
  end

  arches = case (arch_sym = arch&.to_sym)
  when nil
    [SimulateSystem.current_arch]
  when :all
    skip_invalid_combinations = true
    OnSystem::ARCH_OPTIONS
  else
    [arch_sym]
  end

  oses.product(arches).select do |os, arch|
    if skip_invalid_combinations
      bottle_tag = Utils::Bottles::Tag.new(system: os, arch:)
      bottle_tag.valid_combination?
    else
      true
    end
  end
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

#remainingArray<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:



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

def remaining; 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:



97
98
99
100
101
102
103
# File 'cli/args.rb', line 97

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)


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

def verbose?; end