aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2016-10-03 04:03:26 +0200
committerGitHub2016-10-03 04:03:26 +0200
commit35ee2831086e923e7fcaf75fb440b01312e3f9c5 (patch)
tree6f3efd1eb351125333fbe10390bd3a9e5b7b87e0 /Library/Homebrew/cask/lib
parent7d31a70373edae4d8e78d91a4cbc05324bebc3ba (diff)
parente2b3753fd91c47beeb3227a1c0df4c0dfa6026fc (diff)
downloadbrew-1.0.6.tar.bz2
Merge pull request #906 from reitermarkus/os-language1.0.6
Make `MacOS.language` less opinionated and add `language` stanza.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc/auditor.rb17
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask.rb5
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl.rb39
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/base.rb2
5 files changed, 65 insertions, 2 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/auditor.rb b/Library/Homebrew/cask/lib/hbc/auditor.rb
index 6b0c1c476..ee1b50938 100644
--- a/Library/Homebrew/cask/lib/hbc/auditor.rb
+++ b/Library/Homebrew/cask/lib/hbc/auditor.rb
@@ -1,6 +1,23 @@
module Hbc
class Auditor
def self.audit(cask, audit_download: false, check_token_conflicts: false)
+ saved_languages = MacOS.instance_variable_get(:@languages)
+
+ if languages_blocks = cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks)
+ languages_blocks.keys.each do |languages|
+ ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}"
+ MacOS.instance_variable_set(:@languages, languages)
+ audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts)
+ CLI::Cleanup.run(cask.token) if audit_download
+ end
+ else
+ audit_cask_instance(cask, audit_download, check_token_conflicts)
+ end
+ ensure
+ MacOS.instance_variable_set(:@languages, saved_languages)
+ end
+
+ def self.audit_cask_instance(cask, audit_download, check_token_conflicts)
download = audit_download && Download.new(cask)
audit = Audit.new(cask, download: download,
check_token_conflicts: check_token_conflicts)
diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb
index 756b05b83..1e2056efc 100644
--- a/Library/Homebrew/cask/lib/hbc/cask.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask.rb
@@ -11,7 +11,10 @@ module Hbc
@token = token
@sourcefile_path = sourcefile_path
@dsl = dsl || DSL.new(@token)
- @dsl.instance_eval(&block) if block_given?
+ if block_given?
+ @dsl.instance_eval(&block)
+ @dsl.language_eval
+ end
end
DSL::DSL_METHODS.each do |method_name|
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index 3f67e131d..f637ae7af 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -179,6 +179,10 @@ module Hbc
def self.parser
# If you modify these arguments, please update USAGE.md
@parser ||= OptionParser.new do |opts|
+ opts.on("--language STRING") do
+ # handled in OS::Mac
+ end
+
OPTIONS.each do |option, method|
opts.on("#{option}" "PATH", Pathname) do |path|
Hbc.public_send(method, path)
diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb
index 83c0bf1fb..8e0a7715a 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl.rb
@@ -1,4 +1,5 @@
require "set"
+require "locale"
require "hbc/dsl/appcast"
require "hbc/dsl/base"
@@ -64,6 +65,7 @@ module Hbc
:depends_on,
:gpg,
:homepage,
+ :language,
:license,
:name,
:sha256,
@@ -98,6 +100,43 @@ module Hbc
@homepage ||= homepage
end
+ def language(*args, default: false, &block)
+ if !args.empty? && block_given?
+ @language_blocks ||= {}
+ @language_blocks[args] = block
+
+ return unless default
+
+ unless @language_blocks.default.nil?
+ raise CaskInvalidError.new(token, "Only one default language may be defined")
+ end
+
+ @language_blocks.default = block
+ else
+ language_eval
+ end
+ end
+
+ def language_eval
+ return @language if instance_variable_defined?(:@language)
+
+ if @language_blocks.nil? || @language_blocks.empty?
+ return @language = nil
+ end
+
+ MacOS.languages.map(&Locale.method(:parse)).each do |locale|
+ key = @language_blocks.keys.detect { |strings|
+ strings.any? { |string| locale.include?(string) }
+ }
+
+ next if key.nil?
+
+ return @language = @language_blocks[key].call
+ end
+
+ @language = @language_blocks.default.call
+ end
+
def url(*args, &block)
url_given = !args.empty? || block_given?
return @url unless url_given
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/base.rb b/Library/Homebrew/cask/lib/hbc/dsl/base.rb
index ccf93dae9..20a3cec61 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/base.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/base.rb
@@ -8,7 +8,7 @@ module Hbc
@command = command
end
- def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir
+ def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir, :language
def system_command(executable, options = {})
@command.run!(executable, options)