Warn linux users about using --cask
This commit is contained in:
parent
206d9932d2
commit
020c50e588
@ -341,14 +341,20 @@ module Homebrew
|
|||||||
|
|
||||||
@args_parsed = true
|
@args_parsed = true
|
||||||
|
|
||||||
if !ignore_invalid_options && @args.help?
|
unless ignore_invalid_options
|
||||||
|
if @args.help?
|
||||||
puts generate_help_text
|
puts generate_help_text
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
validate_options
|
||||||
|
end
|
||||||
|
|
||||||
@args
|
@args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_options; end
|
||||||
|
|
||||||
def generate_help_text
|
def generate_help_text
|
||||||
Formatter.format_help_text(@parser.to_s, width: COMMAND_DESC_WIDTH)
|
Formatter.format_help_text(@parser.to_s, width: COMMAND_DESC_WIDTH)
|
||||||
.gsub(/\n.*?@@HIDDEN@@.*?(?=\n)/, "")
|
.gsub(/\n.*?@@HIDDEN@@.*?(?=\n)/, "")
|
||||||
@ -701,3 +707,5 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "extend/os/parser"
|
||||||
|
|||||||
20
Library/Homebrew/extend/os/linux/parser.rb
Normal file
20
Library/Homebrew/extend/os/linux/parser.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Homebrew
|
||||||
|
module CLI
|
||||||
|
class Parser
|
||||||
|
undef validate_options
|
||||||
|
|
||||||
|
def validate_options
|
||||||
|
return unless @args.respond_to?(:cask?)
|
||||||
|
return unless @args.cask?
|
||||||
|
|
||||||
|
msg = "Casks are not supported on Linux"
|
||||||
|
raise UsageError, msg unless Homebrew::EnvConfig.developer?
|
||||||
|
|
||||||
|
opoo msg unless @args.quiet?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
4
Library/Homebrew/extend/os/parser.rb
Normal file
4
Library/Homebrew/extend/os/parser.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "extend/os/linux/parser" if OS.linux?
|
||||||
@ -562,4 +562,22 @@ describe Homebrew::CLI::Parser do
|
|||||||
expect { parser.parse(["--not-a-command"]) }.to raise_error(OptionParser::InvalidOption, /--not-a-command/)
|
expect { parser.parse(["--not-a-command"]) }.to raise_error(OptionParser::InvalidOption, /--not-a-command/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "--cask on linux", :needs_linux do
|
||||||
|
subject(:parser) do
|
||||||
|
described_class.new do
|
||||||
|
switch "--cask"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "throws an error for normal users" do
|
||||||
|
allow(Homebrew::EnvConfig).to receive(:developer?).and_return(false)
|
||||||
|
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only warns developers" do
|
||||||
|
allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true)
|
||||||
|
expect { parser.parse(["--cask"]) }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -17,7 +17,7 @@ describe "brew --cache" do
|
|||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prints the cache files for a given Cask", :integration_test do
|
it "prints the cache files for a given Cask", :integration_test, :needs_macos do
|
||||||
expect { brew "--cache", cask_path("local-caffeine") }
|
expect { brew "--cache", cask_path("local-caffeine") }
|
||||||
.to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}o).to_stdout
|
.to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}o).to_stdout
|
||||||
.and output(/Treating #{Regexp.escape(cask_path("local-caffeine"))} as a cask/).to_stderr
|
.and output(/Treating #{Regexp.escape(cask_path("local-caffeine"))} as a cask/).to_stderr
|
||||||
|
|||||||
@ -34,7 +34,7 @@ describe "brew home" do
|
|||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "opens the homepage for a given Cask", :integration_test do
|
it "opens the homepage for a given Cask", :integration_test, :needs_macos do
|
||||||
expect { brew "home", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" }
|
expect { brew "home", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" }
|
||||||
.to output(/#{local_caffeine_homepage}/).to_stdout
|
.to output(/#{local_caffeine_homepage}/).to_stdout
|
||||||
.and output(/Treating #{Regexp.escape(local_caffeine_path)} as a cask/).to_stderr
|
.and output(/Treating #{Regexp.escape(local_caffeine_path)} as a cask/).to_stderr
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user