From 59b099e2cf9c4792e500290cfe22d243079a2b6d Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Tue, 8 Jan 2019 09:25:59 +0000 Subject: [PATCH] Look for config file at ./config/sidekiq.yml by default (if no -r flag provided) --- lib/sidekiq/cli.rb | 12 +++++++----- test/test_cli.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/sidekiq/cli.rb b/lib/sidekiq/cli.rb index 9ea392a26..783cc70c0 100644 --- a/lib/sidekiq/cli.rb +++ b/lib/sidekiq/cli.rb @@ -238,12 +238,14 @@ def setup_options(args) if opts[:config_file] && !File.exist?(opts[:config_file]) raise ArgumentError, "No such file #{opts[:config_file]}" end + elsif opts[:require] && File.directory?(opts[:require]) + %w[config/sidekiq.yml config/sidekiq.yml.erb].each do |filename| + path = File.expand_path(filename, opts[:require]) + opts[:config_file] ||= path if File.exist?(path) + end else - if opts[:require] && File.directory?(opts[:require]) - %w[config/sidekiq.yml config/sidekiq.yml.erb].each do |filename| - path = File.expand_path(filename, opts[:require]) - opts[:config_file] ||= path if File.exist?(path) - end + %w[config/sidekiq.yml config/sidekiq.yml.erb].each do |filename| + opts[:config_file] ||= filename if File.exist?(filename) end end diff --git a/test/test_cli.rb b/test/test_cli.rb index 07aa95729..18c0e8b62 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -254,6 +254,15 @@ class TestCLI < Minitest::Test assert_equal 25, Sidekiq.options[:concurrency] end end + + describe 'when no requirement path is provided' do + it 'tries ./config/sidekiq.yml' do + Dir.chdir("test/dummy") do + @cli.parse(%w[sidekiq]) + assert_equal 'config/sidekiq.yml', Sidekiq.options[:config_file] + end + end + end end end end