
Some of the typing/`T.must` usage when moving the Homebrew/homebrew-services code to Homebrew/brew was not quite correct. Rather than trying to make everything `strict` and import at the same time: let's mostly loosen the typing to fix a few bugs and allow us to add more later.
33 lines
1.0 KiB
Ruby
33 lines
1.0 KiB
Ruby
# typed: true # rubocop:todo Sorbet/StrictSigil
|
|
# frozen_string_literal: true
|
|
|
|
require "services/formula_wrapper"
|
|
|
|
module Homebrew
|
|
module Services
|
|
module Formulae
|
|
# All available services, with optional filters applied
|
|
# @private
|
|
sig { params(loaded: T.nilable(T::Boolean), skip_root: T::Boolean).returns(T::Array[Services::FormulaWrapper]) }
|
|
def self.available_services(loaded: nil, skip_root: false)
|
|
require "formula"
|
|
|
|
formulae = Formula.installed
|
|
.map { |formula| FormulaWrapper.new(formula) }
|
|
.select(&:service?)
|
|
.sort_by(&:name)
|
|
|
|
formulae = formulae.select { |formula| formula.loaded? == loaded } unless loaded.nil?
|
|
formulae = formulae.reject { |formula| formula.owner == "root" } if skip_root
|
|
|
|
formulae
|
|
end
|
|
|
|
# List all available services with status, user, and path to the file.
|
|
def self.services_list
|
|
available_services.map(&:to_hash)
|
|
end
|
|
end
|
|
end
|
|
end
|