Skip to content

Commit

Permalink
Merge pull request #604 from Bo98/disable-restart-file
Browse files Browse the repository at this point in the history
Disable `brew services restart --file=`
  • Loading branch information
MikeMcQuaid authored Dec 11, 2023
2 parents 68336e9 + 79e6161 commit 252a6c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 7 additions & 3 deletions cmd/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ def services
raise UsageError, "The `#{subcommand}` subcommand does not accept the --all argument!" if args.all?
end

if ::Service::Commands::Start::TRIGGERS.include?(subcommand) && args.all? && args.file.present?
raise UsageError, "The start subcommand does not accept the --all and --file= arguments at the same time!"
if args.file
if ::Service::Commands::Start::TRIGGERS.exclude?(subcommand)
raise UsageError, "The `#{subcommand}` subcommand does not accept the --file= argument!"
elsif args.all?
raise UsageError, "The start subcommand does not accept the --all and --file= arguments at the same time!"
end
end

opoo "The --all argument overrides provided formula argument!" if formula.present? && args.all?
Expand All @@ -119,7 +123,7 @@ def services
when *::Service::Commands::Info::TRIGGERS
::Service::Commands::Info.run(targets, verbose: args.verbose?, json: args.json?)
when *::Service::Commands::Restart::TRIGGERS
::Service::Commands::Restart.run(targets, args.file, verbose: args.verbose?)
::Service::Commands::Restart.run(targets, verbose: args.verbose?)
when *::Service::Commands::Run::TRIGGERS
::Service::Commands::Run.run(targets, verbose: args.verbose?)
when *::Service::Commands::Start::TRIGGERS
Expand Down
4 changes: 1 addition & 3 deletions lib/service/commands/restart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ module Restart

TRIGGERS = %w[restart relaunch reload r].freeze

def run(targets, custom_plist, verbose:)
def run(targets, verbose:)
return unless ServicesCli.check(targets)

odeprecated "the restart command with a service file" if custom_plist.present?

ran = []
started = []
targets.each do |service|
Expand Down
8 changes: 4 additions & 4 deletions spec/homebrew/commands/restart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
describe "#run" do
it "fails with empty list" do
expect do
described_class.run([], nil, verbose: false)
described_class.run([], verbose: false)
end.to raise_error UsageError, "Formula(e) missing, please provide a formula name or use --all"
end

Expand All @@ -21,23 +21,23 @@
expect(Service::ServicesCli).not_to receive(:stop)
expect(Service::ServicesCli).to receive(:start).once
service = OpenStruct.new(service_name: "name", loaded?: false)
expect(described_class.run([service], nil, verbose: false)).to be_nil
expect(described_class.run([service], verbose: false)).to be_nil
end

it "starts if services are loaded with file" do
expect(Service::ServicesCli).not_to receive(:run)
expect(Service::ServicesCli).to receive(:start).once
expect(Service::ServicesCli).to receive(:stop).once
service = OpenStruct.new(service_name: "name", loaded?: true, service_file_present?: true)
expect(described_class.run([service], nil, verbose: false)).to be_nil
expect(described_class.run([service], verbose: false)).to be_nil
end

it "runs if services are loaded without file" do
expect(Service::ServicesCli).not_to receive(:start)
expect(Service::ServicesCli).to receive(:run).once
expect(Service::ServicesCli).to receive(:stop).once
service = OpenStruct.new(service_name: "name", loaded?: true, service_file_present?: false)
expect(described_class.run([service], nil, verbose: false)).to be_nil
expect(described_class.run([service], verbose: false)).to be_nil
end
end
end

0 comments on commit 252a6c3

Please sign in to comment.