build_options: typed: strict
Signed-off-by: botantony <antonsm21@gmail.com>
This commit is contained in:
parent
1cc4d0bc25
commit
b2539d37fe
@ -1,11 +1,12 @@
|
||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Options for a formula build.
|
||||
class BuildOptions
|
||||
sig { params(args: Options, options: Options).void }
|
||||
def initialize(args, options)
|
||||
@args = args
|
||||
@options = options
|
||||
@args = T.let(args, Options)
|
||||
@options = T.let(options, Options)
|
||||
end
|
||||
|
||||
# True if a {Formula} is being built with a specific option.
|
||||
@ -29,8 +30,13 @@ class BuildOptions
|
||||
# args << "--with-example1"
|
||||
# end
|
||||
# ```
|
||||
sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) }
|
||||
def with?(val)
|
||||
option_names = val.respond_to?(:option_names) ? val.option_names : [val]
|
||||
option_names = if val.is_a?(String)
|
||||
[val]
|
||||
else
|
||||
val.option_names
|
||||
end
|
||||
|
||||
option_names.any? do |name|
|
||||
if option_defined? "with-#{name}"
|
||||
@ -50,11 +56,13 @@ class BuildOptions
|
||||
# ```ruby
|
||||
# args << "--no-spam-plz" if build.without? "spam"
|
||||
# ```
|
||||
sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) }
|
||||
def without?(val)
|
||||
!with?(val)
|
||||
end
|
||||
|
||||
# True if a {Formula} is being built as a bottle (i.e. binary package).
|
||||
sig { returns(T::Boolean) }
|
||||
def bottle?
|
||||
include? "build-bottle"
|
||||
end
|
||||
@ -75,6 +83,7 @@ class BuildOptions
|
||||
# args << "--and-a-cold-beer" if build.with? "cold-beer"
|
||||
# end
|
||||
# ```
|
||||
sig { returns(T::Boolean) }
|
||||
def head?
|
||||
include? "HEAD"
|
||||
end
|
||||
@ -87,29 +96,35 @@ class BuildOptions
|
||||
# ```ruby
|
||||
# args << "--some-feature" if build.stable?
|
||||
# ```
|
||||
sig { returns(T::Boolean) }
|
||||
def stable?
|
||||
!head?
|
||||
end
|
||||
|
||||
# True if the build has any arguments or options specified.
|
||||
sig { returns(T::Boolean) }
|
||||
def any_args_or_options?
|
||||
!@args.empty? || !@options.empty?
|
||||
end
|
||||
|
||||
sig { returns(Options) }
|
||||
def used_options
|
||||
@options & @args
|
||||
end
|
||||
|
||||
sig { returns(Options) }
|
||||
def unused_options
|
||||
@options - @args
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { params(name: String).returns(T::Boolean) }
|
||||
def include?(name)
|
||||
@args.include?("--#{name}")
|
||||
end
|
||||
|
||||
sig { params(name: String).returns(T::Boolean) }
|
||||
def option_defined?(name)
|
||||
@options.include? name
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user