caveats: print sudo in caveats if service requires it

This commit is contained in:
Sean Molenaar 2022-12-05 12:12:38 +01:00
parent 001bacee18
commit 0cd10ed65e
No known key found for this signature in database
GPG Key ID: AAC1C7E1A4696A9A
2 changed files with 66 additions and 8 deletions

View File

@ -176,10 +176,11 @@ class Caveats
EOS
is_running_service = f.service? && quiet_system("ps aux | grep #{f.service.command&.first}")
startup = f.service&.requires_root? || f.plist_startup
if is_running_service || (f.plist && quiet_system("/bin/launchctl list #{f.plist_name} &>/dev/null"))
s << "To restart #{f.full_name} after an upgrade:"
s << " #{f.plist_startup ? "sudo " : ""}brew services restart #{f.full_name}"
elsif f.plist_startup
s << " #{startup ? "sudo " : ""}brew services restart #{f.full_name}"
elsif startup
s << "To start #{f.full_name} now and restart at startup:"
s << " sudo brew services start #{f.full_name}"
else

View File

@ -172,11 +172,11 @@ describe Caveats do
end
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
allow(Homebrew).to receive(:_system).and_return(true)
allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false)
expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false)
expect(described_class.new(f).caveats).to include("login")
end
it "gives information about restarting services after upgrade" do
it "gives information about plist_options restarting services after upgrade" do
f = formula do
url "foo-1.0"
service do
@ -187,9 +187,66 @@ describe Caveats do
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
f_obj = described_class.new(f)
allow(Homebrew).to receive(:_system).and_return(true)
allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true)
expect(f_obj.caveats).to include("restart #{f.full_name}")
expect(f_obj.caveats).to include("sudo")
expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true)
expect(f_obj.caveats).to include(" sudo brew services restart #{f.full_name}")
end
it "gives information about require_root restarting services after upgrade" do
f = formula do
url "foo-1.0"
service do
run [bin/"cmd"]
require_root true
end
end
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
f_obj = described_class.new(f)
allow(Homebrew).to receive(:_system).and_return(true)
expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true)
expect(f_obj.caveats).to include(" sudo brew services restart #{f.full_name}")
end
it "gives information about user restarting services after upgrade" do
f = formula do
url "foo-1.0"
service do
run [bin/"cmd"]
end
end
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
f_obj = described_class.new(f)
allow(Homebrew).to receive(:_system).and_return(true)
expect(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(true)
expect(f_obj.caveats).to include(" brew services restart #{f.full_name}")
end
it "gives information about require_root starting services after upgrade" do
f = formula do
url "foo-1.0"
service do
run [bin/"cmd"]
require_root true
end
end
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
f_obj = described_class.new(f)
allow(Homebrew).to receive(:_system).and_return(true)
allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false)
expect(f_obj.caveats).to include(" sudo brew services start #{f.full_name}")
end
it "gives information about user starting services after upgrade" do
f = formula do
url "foo-1.0"
service do
run [bin/"cmd"]
end
end
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
f_obj = described_class.new(f)
allow(Homebrew).to receive(:_system).and_return(true)
allow(Homebrew).to receive(:_system).with("ps aux | grep #{cmd}").and_return(false)
expect(f_obj.caveats).to include(" brew services start #{f.full_name}")
end
it "gives information about service manual command" do
@ -203,7 +260,7 @@ describe Caveats do
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
caveats = described_class.new(f).caveats
expect(caveats).to include("background service")
expect(caveats).to include("if you don't want/need a background service")
expect(caveats).to include("VAR=\"foo\" #{cmd} start")
end
end