fix(xbar/brew-services): handle when no brew services are installed

This commit is contained in:
2023-01-29 16:01:45 +00:00
parent cb7ff641f0
commit 9244c7f92b

View File

@@ -2,7 +2,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# <xbar.title>Brew Services</xbar.title> # <xbar.title>Brew Services</xbar.title>
# <xbar.version>v3.0.0</xbar.version> # <xbar.version>v3.0.1</xbar.version>
# <xbar.author>Jim Myhrberg</xbar.author> # <xbar.author>Jim Myhrberg</xbar.author>
# <xbar.author.github>jimeh</xbar.author.github> # <xbar.author.github>jimeh</xbar.author.github>
# <xbar.desc>List and manage Homebrew Services</xbar.desc> # <xbar.desc>List and manage Homebrew Services</xbar.desc>
@@ -283,35 +283,39 @@ module Brew
printer.item(status_label(visible)) do |printer| printer.item(status_label(visible)) do |printer|
printer.sep printer.sep
printer.item(':hourglass: Refresh', refresh: true) printer.item(':hourglass: Refresh', refresh: true)
printer.sep
if visible.stopped.size.positive? unless all_services.empty?
printer.item( printer.sep
"Start All (#{visible.stopped.size} services)", if visible.stopped.size.positive?
terminal: false, refresh: true, printer.item(
shell: [brew_path, 'services', 'start', '--all'] "Start All (#{visible.stopped.size} services)",
) terminal: false, refresh: true,
else shell: [brew_path, 'services', 'start', '--all']
printer.item("Start All (#{visible.stopped.size} services)") )
end else
if visible.started.size.positive? printer.item("Start All (#{visible.stopped.size} services)")
printer.item( end
"Stop All (#{visible.started.size} services)", if visible.started.size.positive?
terminal: false, refresh: true, printer.item(
shell: [brew_path, 'services', 'stop', '--all'] "Stop All (#{visible.started.size} services)",
) terminal: false, refresh: true,
else shell: [brew_path, 'services', 'stop', '--all']
printer.item("Stop All (#{visible.started.size} services)") )
end else
if visible.size.positive? printer.item("Stop All (#{visible.started.size} services)")
count = visible.started.size + visible.stopped.size end
printer.item( if visible.size.positive?
"Restart All (#{count} services)", count = visible.started.size + visible.stopped.size
terminal: false, refresh: true, printer.item(
shell: [brew_path, 'services', 'restart', '--all'] "Restart All (#{count} services)",
) terminal: false, refresh: true,
else shell: [brew_path, 'services', 'restart', '--all']
printer.item("Restart All (#{visible.size} services)") )
else
printer.item("Restart All (#{visible.size} services)")
end
end end
printer.sep printer.sep
if use_groups? if use_groups?
printer.item('Disable groups', rpc: ['disable_groups'], refresh: true) printer.item('Disable groups', rpc: ['disable_groups'], refresh: true)
@@ -493,6 +497,8 @@ module Brew
return @all_services if @all_services return @all_services if @all_services
output = cmd(brew_path, 'services', 'list', '--json') output = cmd(brew_path, 'services', 'list', '--json')
return ServiceList.new([]) if output == ''
data = JSON.parse(output) data = JSON.parse(output)
@all_services = ServiceList.new( @all_services = ServiceList.new(