Add Cask::Config::canonicalize.
This commit is contained in:
parent
defbf7d74c
commit
bcdb4a3f32
@ -6,19 +6,19 @@ using HashValidator
|
|||||||
module Cask
|
module Cask
|
||||||
class Config
|
class Config
|
||||||
DEFAULT_DIRS = {
|
DEFAULT_DIRS = {
|
||||||
appdir: Pathname("/Applications").expand_path,
|
appdir: "/Applications",
|
||||||
prefpanedir: Pathname("~/Library/PreferencePanes").expand_path,
|
prefpanedir: "~/Library/PreferencePanes",
|
||||||
qlplugindir: Pathname("~/Library/QuickLook").expand_path,
|
qlplugindir: "~/Library/QuickLook",
|
||||||
dictionarydir: Pathname("~/Library/Dictionaries").expand_path,
|
dictionarydir: "~/Library/Dictionaries",
|
||||||
fontdir: Pathname("~/Library/Fonts").expand_path,
|
fontdir: "~/Library/Fonts",
|
||||||
colorpickerdir: Pathname("~/Library/ColorPickers").expand_path,
|
colorpickerdir: "~/Library/ColorPickers",
|
||||||
servicedir: Pathname("~/Library/Services").expand_path,
|
servicedir: "~/Library/Services",
|
||||||
input_methoddir: Pathname("~/Library/Input Methods").expand_path,
|
input_methoddir: "~/Library/Input Methods",
|
||||||
internet_plugindir: Pathname("~/Library/Internet Plug-Ins").expand_path,
|
internet_plugindir: "~/Library/Internet Plug-Ins",
|
||||||
audio_unit_plugindir: Pathname("~/Library/Audio/Plug-Ins/Components").expand_path,
|
audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components",
|
||||||
vst_plugindir: Pathname("~/Library/Audio/Plug-Ins/VST").expand_path,
|
vst_plugindir: "~/Library/Audio/Plug-Ins/VST",
|
||||||
vst3_plugindir: Pathname("~/Library/Audio/Plug-Ins/VST3").expand_path,
|
vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3",
|
||||||
screen_saverdir: Pathname("~/Library/Screen Savers").expand_path,
|
screen_saverdir: "~/Library/Screen Savers",
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def self.global
|
def self.global
|
||||||
@ -45,33 +45,38 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
new(
|
new(
|
||||||
default: config.fetch("default", {}).map { |k, v| [k.to_sym, Pathname(v).expand_path] }.to_h,
|
default: config.fetch("default", {}),
|
||||||
env: config.fetch("env", {}).map { |k, v| [k.to_sym, Pathname(v).expand_path] }.to_h,
|
env: config.fetch("env", {}),
|
||||||
explicit: config.fetch("explicit", {}).map { |k, v| [k.to_sym, Pathname(v).expand_path] }.to_h,
|
explicit: config.fetch("explicit", {}),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.canonicalize(config)
|
||||||
|
config.map { |k, v| [k.to_sym, Pathname(v).expand_path] }.to_h
|
||||||
|
end
|
||||||
|
|
||||||
attr_accessor :explicit
|
attr_accessor :explicit
|
||||||
|
|
||||||
def initialize(default: nil, env: nil, explicit: {})
|
def initialize(default: nil, env: nil, explicit: {})
|
||||||
env&.assert_valid_keys!(*DEFAULT_DIRS.keys)
|
@default = self.class.canonicalize(default) if default
|
||||||
explicit.assert_valid_keys!(*DEFAULT_DIRS.keys)
|
@env = self.class.canonicalize(env) if env
|
||||||
|
@explicit = self.class.canonicalize(explicit)
|
||||||
|
|
||||||
@default = default
|
@env&.assert_valid_keys!(*DEFAULT_DIRS.keys)
|
||||||
@env = env
|
@explicit.assert_valid_keys!(*DEFAULT_DIRS.keys)
|
||||||
@explicit = explicit.map { |(k, v)| [k.to_sym, Pathname(v).expand_path] }.to_h
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def default
|
def default
|
||||||
@default ||= DEFAULT_DIRS
|
@default ||= self.class.canonicalize(DEFAULT_DIRS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def env
|
def env
|
||||||
@env ||= Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", ""))
|
@env ||= self.class.canonicalize(
|
||||||
.select { |arg| arg.include?("=") }
|
Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", ""))
|
||||||
.map { |arg| arg.split("=", 2) }
|
.select { |arg| arg.include?("=") }
|
||||||
.map { |(flag, value)| [flag.sub(/^\-\-/, "").to_sym, Pathname(value).expand_path] }
|
.map { |arg| arg.split("=", 2) }
|
||||||
.to_h
|
.map { |(flag, value)| [flag.sub(/^\-\-/, ""), value] },
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def binarydir
|
def binarydir
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user