Completions, Settings: move to Homebrew namespace

This commit is contained in:
Rylan Polster 2021-01-13 11:16:09 -05:00
parent eb3a662841
commit 4b8477ba70
11 changed files with 114 additions and 99 deletions

View File

@ -92,7 +92,7 @@ begin
internal_cmd ||= begin
internal_dev_cmd = Commands.valid_internal_dev_cmd?(cmd)
if internal_dev_cmd && !Homebrew::EnvConfig.developer?
Settings.write "devcmdrun", true
Homebrew::Settings.write "devcmdrun", true
ENV["HOMEBREW_DEV_CMD_RUN"] = "1"
end
internal_dev_cmd

View File

@ -4,14 +4,17 @@
require "utils/link"
require "settings"
# Helper functions for generating shell completions.
#
# @api private
module Completions
module Homebrew
# Helper functions for generating shell completions.
#
# @api private
module Completions
extend T::Sig
module_function
SHELLS = %w[bash fish zsh].freeze
sig { void }
def link!
Settings.write :linkcompletions, true
@ -37,11 +40,10 @@ module Completions
sig { returns(T::Boolean) }
def completions_to_link?
shells = %w[bash fish zsh]
Tap.each do |tap|
next if tap.official?
shells.each do |shell|
SHELLS.each do |shell|
return true if (tap.path/"completions/#{shell}").exist?
end
end
@ -54,8 +56,8 @@ module Completions
return if Settings.read(:completionsmessageshown) == "true"
return unless completions_to_link?
T.unsafe(self).ohai "Homebrew completions for external commands are unlinked by default!"
T.unsafe(self).puts <<~EOS
ohai "Homebrew completions for external commands are unlinked by default!"
puts <<~EOS
To opt-in to automatically linking external tap shell competion files, run:
brew completions link
Then, follow the directions at #{Formatter.url("https://docs.brew.sh/Shell-Completion")}
@ -63,4 +65,5 @@ module Completions
Settings.write :completionsmessageshown, true
end
end
end

View File

@ -0,0 +1,7 @@
# typed: strict
module Homebrew
module Completions
include Kernel
end
end

View File

@ -1,10 +1,11 @@
# typed: true
# frozen_string_literal: true
# Helper functions for reading and writing settings.
#
# @api private
module Settings
module Homebrew
# Helper functions for reading and writing settings.
#
# @api private
module Settings
extend T::Sig
module_function
@ -23,7 +24,7 @@ module Settings
return unless (repo/".git/config").exist?
repo.cd do
T.unsafe(self).safe_system "git", "config", "--replace-all", "homebrew.#{setting}", value.to_s
safe_system "git", "config", "--replace-all", "homebrew.#{setting}", value.to_s
end
end
@ -33,7 +34,8 @@ module Settings
return if read(setting, repo: repo).blank?
repo.cd do
T.unsafe(self).safe_system "git", "config", "--unset-all", "homebrew.#{setting}"
safe_system "git", "config", "--unset-all", "homebrew.#{setting}"
end
end
end
end

View File

@ -0,0 +1,7 @@
# typed: strict
module Homebrew
module Settings
include Kernel
end
end

View File

@ -343,8 +343,8 @@ class Tap
command = "brew tap --repair"
Utils::Link.link_manpages(path, command)
Completions.show_completions_message_if_needed
if official? || Completions.link_completions?
Homebrew::Completions.show_completions_message_if_needed
if official? || Homebrew::Completions.link_completions?
Utils::Link.link_completions(path, command)
else
Utils::Link.unlink_completions(path)
@ -822,14 +822,14 @@ class TapConfig
return unless tap.git?
return unless Utils::Git.available?
Settings.read key, repo: tap.path
Homebrew::Settings.read key, repo: tap.path
end
def []=(key, value)
return unless tap.git?
return unless Utils::Git.available?
Settings.write key, value.to_s, repo: tap.path
Homebrew::Settings.write key, value.to_s, repo: tap.path
end
end

View File

@ -22,7 +22,7 @@ RSpec/InstanceVariable:
- 'utils/git_spec.rb'
- 'version_spec.rb'
# Offense count: 81
# Offense count: 76
RSpec/MultipleDescribes:
Exclude:
- 'ENV_spec.rb'
@ -37,7 +37,6 @@ RSpec/MultipleDescribes:
- 'cmd/autoremove_spec.rb'
- 'cmd/cleanup_spec.rb'
- 'cmd/commands_spec.rb'
- 'cmd/completions_spec.rb'
- 'cmd/config_spec.rb'
- 'cmd/deps_spec.rb'
- 'cmd/desc_spec.rb'

View File

@ -3,12 +3,12 @@
require "cmd/shared_examples/args_parse"
describe "Homebrew.completions_args" do
describe "brew completions" do
describe "Homebrew.completions_args" do
it_behaves_like "parseable arguments"
end
end
describe "brew completions", :integration_test do
it "runs the status subcommand correctly" do
it "runs the status subcommand correctly", :integration_test do
HOMEBREW_REPOSITORY.cd do
system "git", "init"
end

View File

@ -3,7 +3,7 @@
require "completions"
describe Completions do
describe Homebrew::Completions do
let(:internal_path) { HOMEBREW_REPOSITORY/"Library/Taps/homebrew/homebrew-bar" }
let(:external_path) { HOMEBREW_REPOSITORY/"Library/Taps/foo/homebrew-bar" }
@ -132,12 +132,9 @@ describe Completions do
setup_completions external: true
delete_completions_setting setting: :completionsmessageshown
# This will fail because the method calls `puts`.
# If we output the `ohai` andcatch the error, we can be usre that the message is showing.
error_message = "private method `puts' called for Completions:Module"
message = /Homebrew completions for external commands are unlinked by default!/
expect { described_class.show_completions_message_if_needed }
.to output.to_stdout
.and raise_error(NoMethodError, error_message)
.to output(message).to_stdout
end
end
end

View File

@ -3,7 +3,7 @@
require "settings"
describe Settings do
describe Homebrew::Settings do
before do
HOMEBREW_REPOSITORY.cd do
system "git", "init"

View File

@ -103,27 +103,27 @@ module Utils
end
def uuid
Settings.read :analyticsuuid
Homebrew::Settings.read :analyticsuuid
end
def messages_displayed!
Settings.write :analyticsmessage, true
Settings.write :caskanalyticsmessage, true
Homebrew::Settings.write :analyticsmessage, true
Homebrew::Settings.write :caskanalyticsmessage, true
end
def enable!
Settings.write :analyticsdisabled, false
Homebrew::Settings.write :analyticsdisabled, false
messages_displayed!
end
def disable!
Settings.write :analyticsdisabled, true
Homebrew::Settings.write :analyticsdisabled, true
regenerate_uuid!
end
def regenerate_uuid!
# it will be regenerated in next run unless disabled.
Settings.delete :analyticsuuid
Homebrew::Settings.delete :analyticsuuid
end
def output(args:, filter: nil)
@ -314,7 +314,7 @@ module Utils
end
def config_true?(key)
Settings.read(key) == "true"
Homebrew::Settings.read(key) == "true"
end
def formulae_brew_sh_json(endpoint)