Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add available languages to cask info command #3220

Merged
merged 2 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Library/Homebrew/cask/lib/hbc/cli/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def self.info(cask)
installation_info(cask)
repo_info(cask)
name_info(cask)
language_info(cask)
artifact_info(cask)
Installer.print_caveats(cask)
end
Expand Down Expand Up @@ -51,6 +52,13 @@ def self.name_info(cask)
puts cask.name.empty? ? Formatter.error("None") : cask.name
end

def self.language_info(cask)
return if cask.languages.empty?

ohai "Languages"
puts cask.languages.join(", ")
end

def self.repo_info(cask)
user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token })

Expand Down
7 changes: 7 additions & 0 deletions Library/Homebrew/cask/lib/hbc/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DSL
:gpg,
:homepage,
:language,
:languages,
:name,
:sha256,
:staged_path,
Expand Down Expand Up @@ -139,6 +140,12 @@ def language_eval
@language = @language_blocks.default.call
end

def languages
return [] if @language_blocks.nil?

@language_blocks.keys.flatten
end

def url(*args, &block)
set_unique_stanza(:url, args.empty? && !block_given?) do
begin
Expand Down
32 changes: 32 additions & 0 deletions Library/Homebrew/test/cask/cli/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@
EOS
end

it "prints languages specified in the Cask" do
expect {
Hbc::CLI::Info.run("with-languages")
}.to output(<<-EOS.undent).to_stdout
with-languages: 1.2.3
http://example.com/local-caffeine
Not installed
From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-languages.rb
==> Name
None
==> Languages
zh, en-US
==> Artifacts
Caffeine.app (App)
EOS
end

it 'does not print "Languages" section divider if the languages block has no output' do
expect {
Hbc::CLI::Info.run("without-languages")
}.to output(<<-EOS.undent).to_stdout
without-languages: 1.2.3
http://example.com/local-caffeine
Not installed
From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/without-languages.rb
==> Name
None
==> Artifacts
Caffeine.app (App)
EOS
end

describe "when no Cask is specified" do
it "raises an exception" do
expect {
Expand Down
30 changes: 30 additions & 0 deletions Library/Homebrew/test/cask/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,36 @@
expect(cask.call.sha256).to eq("xyz789")
expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip")
end

it "returns an empty array if no languages are specified" do
cask = lambda do
Hbc::Cask.new("cask-with-apps") do
url "https://example.org/file.zip"
end
end

expect(cask.call.languages).to be_empty
end

it "returns an array of available languages" do
cask = lambda do
Hbc::Cask.new("cask-with-apps") do
language "zh" do
sha256 "abc123"
"zh-CN"
end

language "en-US", default: true do
sha256 "xyz789"
"en-US"
end

url "https://example.org/file.zip"
end
end

expect(cask.call.languages).to eq(["zh", "en-US"])
end
end

describe "app stanza" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cask 'with-languages' do
version '1.2.3'

language "zh" do
sha256 "abc123"
"zh-CN"
end

language "en-US", default: true do
sha256 "xyz789"
"en-US"
end

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'http://example.com/local-caffeine'

app 'Caffeine.app'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cask 'without-languages' do
version '1.2.3'
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'http://example.com/local-caffeine'

app 'Caffeine.app'
end