Skip to content

Commit

Permalink
Default to watchexec when installed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 committed Dec 1, 2024
1 parent 5a0fb3d commit 1993177
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
9 changes: 7 additions & 2 deletions exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Signal.trap(:INT) do
end

options = Retest::Options.new(ARGV)
puts "Watcher: [#{options.watcher.upcase}]"

if options.help?
$stdout.puts options.help
Expand All @@ -28,8 +27,14 @@ prompt = Retest::Prompt.new
repository = Retest::Repository.new(files: Retest::VersionControl.files, prompt: prompt)
command = Retest::Command.for_options(options)
runner = Retest::Runner.new(command)
watcher = Retest::Watcher.for(options.watcher)
sounds = Retest::Sounds.for(options)
watcher = Retest::Watcher.for(options.watcher).tap do |tool|
if tool == Retest::Watcher::Watchexec
puts "Watcher: [WATCHEXEC]"
else Retest::Watcher::Default
puts "Watcher: [LISTEN]"
end
end

sounds.play(:start)
runner.add_observer(sounds)
Expand Down
2 changes: 1 addition & 1 deletion lib/retest/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def extensions
end

def watcher
params[:watcher] || :listen
params[:watcher] || :installed
end

def merge(options = [])
Expand Down
9 changes: 7 additions & 2 deletions lib/retest/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module Retest
module Watcher
def self.for(watcher)
tool = case watcher.to_s
when 'listen' then Default
when 'watchexec' then Watchexec
when 'listen' then Default
when 'watchexec' then Watchexec
when '', 'installed' then installed
else raise ArgumentError, "Unknown #{watcher}"
end

Expand All @@ -14,6 +15,10 @@ def self.for(watcher)
tool
end

def self.installed
[Watchexec, Default].find(&:installed?)
end

module Default
def self.installed?
true
Expand Down
4 changes: 2 additions & 2 deletions test/retest/options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def test_listener
assert_equal :listen, @subject.watcher

@subject.args = %w[-w hello]
assert_equal :listen, @subject.watcher
assert_equal :installed, @subject.watcher

@subject.args = %w[] # default when no listeners are install by default
assert_equal :listen, @subject.watcher
assert_equal :installed, @subject.watcher
end
end
end
3 changes: 2 additions & 1 deletion test/retest/watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ class TestWatcher < Minitest::Test
def test_for
assert_equal Watcher::Default, Watcher.for('listen')
assert_equal Watcher::Watchexec, Watcher.for('watchexec')
assert_equal Watcher::Watchexec, Watcher.for(nil)

assert_raises(ArgumentError) { Watcher.for(nil) }
assert_raises(ArgumentError) { Watcher.for('fswatch') }
end
end

Expand Down

0 comments on commit 1993177

Please sign in to comment.