2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
module Artifact
|
|
|
|
class Base
|
|
|
|
def self.artifact_name
|
2016-10-14 20:03:34 +02:00
|
|
|
@artifact_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.artifact_english_name
|
2016-10-14 20:03:34 +02:00
|
|
|
@artifact_english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2')
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.artifact_english_article
|
2017-05-29 18:24:52 +01:00
|
|
|
@artifact_english_article ||= (artifact_english_name =~ /^[aeiou]/i) ? "an" : "a"
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.artifact_dsl_key
|
|
|
|
@artifact_dsl_key ||= artifact_name.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.artifact_dirmethod
|
|
|
|
@artifact_dirmethod ||= "#{artifact_name}dir".to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.me?(cask)
|
|
|
|
cask.artifacts[artifact_dsl_key].any?
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :force
|
|
|
|
|
|
|
|
# TODO: this sort of logic would make more sense in dsl.rb, or a
|
|
|
|
# constructor called from dsl.rb, so long as that isn't slow.
|
|
|
|
def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
|
|
|
|
# TODO: when stanza names are harmonized with class names,
|
|
|
|
# stanza may not be needed as an explicit argument
|
2017-03-10 09:33:48 +01:00
|
|
|
description = key ? "#{stanza} #{key.inspect}" : stanza.to_s
|
2016-09-24 13:52:43 +02:00
|
|
|
|
|
|
|
# backward-compatible string value
|
|
|
|
arguments = { executable: arguments } if arguments.is_a?(String)
|
|
|
|
|
|
|
|
# key sanity
|
2016-12-31 18:02:42 +01:00
|
|
|
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
|
2016-09-24 13:52:43 +02:00
|
|
|
unknown_keys = arguments.keys - permitted_keys
|
|
|
|
unless unknown_keys.empty?
|
|
|
|
opoo %Q{Unknown arguments to #{description} -- #{unknown_keys.inspect} (ignored). Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.}
|
|
|
|
end
|
2017-05-29 18:24:52 +01:00
|
|
|
arguments.select! { |k| permitted_keys.include?(k) }
|
2016-09-24 13:52:43 +02:00
|
|
|
|
|
|
|
# key warnings
|
|
|
|
override_keys = override_arguments.keys
|
|
|
|
ignored_keys = arguments.keys & override_keys
|
|
|
|
unless ignored_keys.empty?
|
|
|
|
onoe "Some arguments to #{description} will be ignored -- :#{unknown_keys.inspect} (overridden)."
|
|
|
|
end
|
|
|
|
|
|
|
|
# extract executable
|
|
|
|
executable = arguments.key?(:executable) ? arguments.delete(:executable) : nil
|
|
|
|
|
|
|
|
arguments = default_arguments.merge arguments
|
|
|
|
arguments.merge! override_arguments
|
|
|
|
|
|
|
|
[executable, arguments]
|
|
|
|
end
|
|
|
|
|
|
|
|
def summary
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
2017-05-21 00:15:56 +02:00
|
|
|
def verbose?
|
|
|
|
@verbose
|
|
|
|
end
|
|
|
|
|
|
|
|
def force?
|
|
|
|
@force
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(cask, command: SystemCommand, force: false, verbose: false)
|
2016-09-24 13:52:43 +02:00
|
|
|
@cask = cask
|
|
|
|
@command = command
|
|
|
|
@force = force
|
2017-05-21 00:15:56 +02:00
|
|
|
@verbose = verbose
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|