Class: Homebrew::CLI::Args
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Homebrew::CLI::Args
show all
- Defined in:
- cli/args.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ void
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'cli/args.rb', line 15
def initialize
require "cli/named_args"
super()
@processed_options = []
@options_only = []
@flags_only = []
@cask_options = false
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) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
|
# File 'cli/args.rb', line 169
def method_missing(method_name, *args)
return_value = super
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_only ⇒ Object
Returns the value of attribute flags_only.
9
10
11
|
# File 'cli/args.rb', line 9
def flags_only
@flags_only
end
|
#options_only ⇒ Object
Returns the value of attribute options_only.
9
10
11
|
# File 'cli/args.rb', line 9
def options_only
@options_only
end
|
Instance Method Details
70
71
72
73
74
75
76
|
# File 'cli/args.rb', line 70
def build_from_source_formulae
if build_from_source? || self[:HEAD?] || self[:build_bottle?]
named.to_formulae.map(&:full_name)
else
[]
end
end
|
95
96
97
|
# File 'cli/args.rb', line 95
def context
Context::ContextStruct.new(debug: debug?, quiet: quiet?, verbose: verbose?)
end
|
#freeze_named_args!(named_args, cask_options:, without_api:) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'cli/args.rb', line 35
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: cask_options,
without_api: without_api,
**options,
)
end
|
#freeze_processed_options!(processed_options) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'cli/args.rb', line 49
def freeze_processed_options!(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
31
32
33
|
# File 'cli/args.rb', line 31
def freeze_remaining_args!(remaining_args)
self[:remaining] = remaining_args.freeze
end
|
78
79
80
81
82
83
84
|
# File 'cli/args.rb', line 78
def include_test_formulae
if include_test?
named.to_formulae.map(&:full_name)
else
[]
end
end
|
61
62
63
64
|
# File 'cli/args.rb', line 61
def named
require "formula"
self[:named]
end
|
#no_named? ⇒ Boolean
66
67
68
|
# File 'cli/args.rb', line 66
def no_named?
named.blank?
end
|
99
100
101
102
|
# File 'cli/args.rb', line 99
def only_formula_or_cask
return :formula if formula? && !cask?
return :cask if cask? && !formula?
end
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'cli/args.rb', line 105
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: arch)
bottle_tag.valid_combination?
else
true
end
end
end
|
#value(name) ⇒ Object
86
87
88
89
90
91
92
|
# File 'cli/args.rb', line 86
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
|