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 1 commit
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
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
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
Expand Up @@ -90,6 +90,38 @@
EOS
end

it "should print languages if the Cask provided any" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prints languages specified in the Cask

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 'should not print "Languages" section divider if the languages block has no output' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not print

expect {
Hbc::CLI::Info.run("with-conditional-languages")
}.to output(<<-EOS.undent).to_stdout
with-conditional-languages: 1.2.3
http://example.com/local-caffeine
Not installed
From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-conditional-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
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 empty array if no languages specified" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an empty array … are specified

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
@@ -0,0 +1,9 @@
cask 'with-conditional-languages' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without-languages

version '1.2.3'
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

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

app 'Caffeine.app'
end
@@ -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