From f39fb5d6b2dfadeae4c4e3a0d904e576f0f80c21 Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Fri, 29 Jan 2021 17:11:14 -0500 Subject: [PATCH] cask/config: new method for cask.config.explicit as string --- Library/Homebrew/cask/config.rb | 14 +++++++++++++- Library/Homebrew/test/cask/config_spec.rb | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index b7ae4565e6..44702025a5 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -127,7 +127,7 @@ module Cask .map { |arg| T.cast(arg.split("=", 2), [String, String]) } .map do |(flag, value)| key = flag.sub(/^--/, "") - + # converts --language flag to :languages config key if key == "language" key = "languages" value = value.split(",") @@ -182,6 +182,18 @@ module Cask self.class.new(explicit: other.explicit.merge(explicit)) end + sig { returns(String) } + def explicit_s + explicit.map do |key, value| + # inverse of #env - converts :languages config key back to --language flag + if key == :languages + key = "language" + value = languages.join(",") + end + "#{key}: \"#{value.to_s.sub(/^#{ENV['HOME']}/, "~")}\"" + end.join(", ") + end + sig { params(options: T.untyped).returns(String) } def to_json(**options) { diff --git a/Library/Homebrew/test/cask/config_spec.rb b/Library/Homebrew/test/cask/config_spec.rb index 86cd911675..aad0d27b5a 100644 --- a/Library/Homebrew/test/cask/config_spec.rb +++ b/Library/Homebrew/test/cask/config_spec.rb @@ -60,11 +60,22 @@ describe Cask::Config, :cask do end describe "#explicit" do - let(:config) { described_class.new(explicit: { appdir: "/explicit/path/to/apps" }) } + let(:config) { + described_class.new(explicit: { appdir: "/explicit/path/to/apps", + languages: ["zh-TW", "en"] }) + } it "returns directories explicitly given as arguments" do expect(config.explicit[:appdir]).to eq(Pathname("/explicit/path/to/apps")) end + + it "returns array of preferred languages" do + expect(config.explicit[:languages]).to eq(["zh-TW", "en"]) + end + + it "returns string of explicit config keys and values" do + expect(config.explicit_s).to eq('appdir: "/explicit/path/to/apps", language: "zh-TW,en"') + end end context "when installing a cask and then adding a global default dir" do