when-files-change 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/when-files-change +8 -1
- data/lib/change_listener.rb +28 -4
- metadata +3 -3
data/bin/when-files-change
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
require File.dirname(__FILE__) + '/../lib/change_listener'
|
4
4
|
|
5
|
-
# Options
|
5
|
+
# Default Options
|
6
6
|
ignored_paths = nil
|
7
|
+
verbose = false
|
7
8
|
|
8
9
|
opts = OptionParser.new do |opts|
|
9
10
|
opts.banner = "Usage: #{File.basename($0)} [options] -- command [arguments]"
|
@@ -12,6 +13,11 @@ opts = OptionParser.new do |opts|
|
|
12
13
|
opts.on("-i", "--ignore PATHS", Array, "Ignore changes made at these paths") do |paths|
|
13
14
|
ignore_paths = paths
|
14
15
|
end
|
16
|
+
|
17
|
+
opts.on("-v", "--verbose", "Enable verbose mode") do
|
18
|
+
verbose = true
|
19
|
+
end
|
20
|
+
|
15
21
|
opts.parse! ARGV
|
16
22
|
end
|
17
23
|
|
@@ -23,6 +29,7 @@ end
|
|
23
29
|
|
24
30
|
listener = ChangeListener.new(command, *ARGV)
|
25
31
|
listener.ignore_paths(ignored_paths) if ignored_paths
|
32
|
+
listener.verbose = verbose
|
26
33
|
listener.start
|
27
34
|
|
28
35
|
# Catch signals so we can exit gracefully
|
data/lib/change_listener.rb
CHANGED
@@ -5,32 +5,56 @@ class ChangeListener
|
|
5
5
|
attr_reader :listener
|
6
6
|
attr_reader :command
|
7
7
|
attr_reader :arguments
|
8
|
+
attr_accessor :verbose
|
9
|
+
attr_accessor :out
|
8
10
|
|
9
11
|
def initialize(command, *arguments)
|
10
12
|
@command = command
|
11
13
|
@arguments = arguments
|
12
|
-
@
|
14
|
+
@out = STDERR
|
13
15
|
|
16
|
+
@listener = Listen.to('./').ignore(/^\.\w+/)
|
14
17
|
@listener.change{ execute }
|
15
18
|
end
|
16
19
|
|
17
20
|
def start
|
21
|
+
out.puts "Listening..." if verbose?
|
18
22
|
listener.start(false)
|
19
23
|
end
|
20
24
|
|
21
25
|
def execute
|
22
26
|
listener.pause
|
23
|
-
|
27
|
+
run_command
|
24
28
|
listener.unpause
|
25
29
|
end
|
26
30
|
|
27
31
|
def ignore(*regexps)
|
28
|
-
|
32
|
+
listener.ignore(*regexps)
|
29
33
|
end
|
30
34
|
|
31
35
|
def ignore_path(*paths)
|
32
36
|
globs = paths.map{|p| FileGlob.new(p)}
|
33
37
|
|
34
|
-
|
38
|
+
listener.ignore(*globs)
|
39
|
+
end
|
40
|
+
|
41
|
+
def verbose?
|
42
|
+
verbose
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def run_command
|
48
|
+
out.puts command_to_s if verbose?
|
49
|
+
success = Kernel.system(ENV, command, *arguments)
|
50
|
+
report_error unless success
|
51
|
+
end
|
52
|
+
|
53
|
+
def report_error
|
54
|
+
out.puts "* Exited with #{$?.exitstatus}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def command_to_s
|
58
|
+
"#{command} #{arguments.join(' ')}"
|
35
59
|
end
|
36
60
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Sanderson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2013-
|
17
|
+
date: 2013-05-09 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|