Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create lanes with non optional parameters and raises an error if we try to access a missing value from the `option` hash
###### BEFORE ######
lane :test do
build
end
lane :build do |options|
scheme = options[:scheme]
# ...
end
# => scheme is missing but execution continues (which can lead to problems later)
###### AFTER ######
lane :test do
build
end
secure_lane :build do |options|
scheme = options[:scheme]
# ...
end
# => scheme is missing but we get the exception: "Can't find value for key :scheme in lane :build"
class Fastlane::FastFile # from https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/fast_file.rb
# Hash that raises an error when we access a missing value
class RequiredOptions < Hash
def initialize(options, lane)
options.each { |key, value| self[key] = value }
@lane = lane
end
def [](key)
value = super(key)
UI.user_error!("Can't find value for key :#{key} in lane :#{@lane}") if value.nil?
value
end
end
def secure_lane(name, &block)
lane(name) do |options|
options = RequiredOptions.new(options, name)
block.call(options)
end
end
def secure_private_lane(name, &block)
private_lane(name) do |options|
options = RequiredOptions.new(options, name)
block.call(options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.