Class: Homebrew::CLI::Args

Inherits:
OpenStruct
  • Object
show all
Defined in:
Library/Homebrew/cli/args.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArgs

Returns a new instance of Args.


15
16
17
18
19
20
21
22
23
24
25
26
# File 'Library/Homebrew/cli/args.rb', line 15

def initialize
  super()

  @processed_options = []
  @options_only = []
  @flags_only = []

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

Instance Attribute Details

#flags_onlyObject (readonly)

Returns the value of attribute flags_only


10
11
12
# File 'Library/Homebrew/cli/args.rb', line 10

def flags_only
  @flags_only
end

#options_onlyObject (readonly)

Returns the value of attribute options_only


10
11
12
# File 'Library/Homebrew/cli/args.rb', line 10

def options_only
  @options_only
end

Instance Method Details

#build_from_source_formulaeObject


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

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

#build_stable?Boolean

Returns:

  • (Boolean)

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

def build_stable?
  !HEAD?
end

#casksObject


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

def casks
  odeprecated "args.casks", "args.named.homebrew_tap_cask_names"
  named.homebrew_tap_cask_names
end

#contextObject


134
135
136
# File 'Library/Homebrew/cli/args.rb', line 134

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

#formulaeObject


61
62
63
64
# File 'Library/Homebrew/cli/args.rb', line 61

def formulae
  odeprecated "args.formulae", "args.named.to_formulae"
  named.to_formulae
end

#formulae_and_casksObject


66
67
68
69
# File 'Library/Homebrew/cli/args.rb', line 66

def formulae_and_casks
  odeprecated "args.formulae_and_casks", "args.named.to_formulae_and_casks"
  named.to_formulae_and_casks
end

#formulae_pathsObject


81
82
83
84
# File 'Library/Homebrew/cli/args.rb', line 81

def formulae_paths
  odeprecated "args.formulae_paths", "args.named.to_formulae_paths"
  named.to_formulae_paths
end

#freeze_named_args!(named_args) ⇒ Object


32
33
34
35
36
37
38
39
40
# File 'Library/Homebrew/cli/args.rb', line 32

def freeze_named_args!(named_args)
  self[:named_args] = NamedArgs.new(
    *named_args.freeze,
    override_spec: spec(nil),
    force_bottle:  force_bottle?,
    flags:         flags_only,
    parent:        self,
  )
end

#freeze_processed_options!(processed_options) ⇒ Object


42
43
44
45
46
47
48
49
50
51
# File 'Library/Homebrew/cli/args.rb', line 42

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

#freeze_remaining_args!(remaining_args) ⇒ Object


28
29
30
# File 'Library/Homebrew/cli/args.rb', line 28

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

#include_test_formulaeObject


118
119
120
121
122
123
124
# File 'Library/Homebrew/cli/args.rb', line 118

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

#kegsObject


96
97
98
99
# File 'Library/Homebrew/cli/args.rb', line 96

def kegs
  odeprecated "args.kegs", "args.named.to_kegs"
  named.to_kegs
end

#kegs_casksObject


101
102
103
104
# File 'Library/Homebrew/cli/args.rb', line 101

def kegs_casks
  odeprecated "args.kegs", "args.named.to_kegs_to_casks"
  named.to_kegs_to_casks
end

#loaded_casksObject


91
92
93
94
# File 'Library/Homebrew/cli/args.rb', line 91

def loaded_casks
  odeprecated "args.loaded_casks", "args.named.to_cask"
  named.to_casks
end

#namedObject


53
54
55
# File 'Library/Homebrew/cli/args.rb', line 53

def named
  named_args
end

#no_named?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'Library/Homebrew/cli/args.rb', line 57

def no_named?
  named.blank?
end

#resolved_formulaeObject


71
72
73
74
# File 'Library/Homebrew/cli/args.rb', line 71

def resolved_formulae
  odeprecated "args.resolved_formulae", "args.named.to_resolved_formulae"
  named.to_resolved_formulae
end

#resolved_formulae_casksObject


76
77
78
79
# File 'Library/Homebrew/cli/args.rb', line 76

def resolved_formulae_casks
  odeprecated "args.resolved_formulae_casks", "args.named.to_resolved_formulae_to_casks"
  named.to_resolved_formulae_to_casks
end

#value(name) ⇒ Object


126
127
128
129
130
131
132
# File 'Library/Homebrew/cli/args.rb', line 126

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