snooper 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/snooper +12 -1
- data/lib/snooper.rb +1 -0
- data/lib/snooper/hook.rb +62 -0
- data/lib/snooper/hook.rb~ +17 -0
- data/lib/snooper/snoop.rb +26 -5
- data/lib/snooper/version.rb +1 -1
- data/man/snooper-config.7 +21 -1
- data/man/snooper-config.7.html +26 -1
- data/man/snooper-config.7.ronn +23 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 634956e753d4252eb400d1e90476e5dba0dfb71b
|
4
|
+
data.tar.gz: 48822ec94381e1dde8c9a576aaf3467b1c4192fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ffcae7b1adb30d9d1a0e3d85ded93dc9b0e67afd7234e1fa52df6c61df60dcc0a80066598aadc3f47e8e81d734fd2342b2f559cc751ef7d071eca2a2ac9e74e
|
7
|
+
data.tar.gz: 294184c9327a8084d66001631931c54db89ce1211ad2d53847e93b3a31fd1315751c184d3a6735a4750c58f287a386e383368be8dae65923db1573010a4ef6b1
|
data/bin/snooper
CHANGED
@@ -51,6 +51,11 @@ END
|
|
51
51
|
opts.on '-c', '--config CONFIGFILE', 'YAML configuration file' do |path|
|
52
52
|
config_path = path
|
53
53
|
end
|
54
|
+
|
55
|
+
opts.on("--version", "show version information") do
|
56
|
+
puts "Snooper v#{Snooper::VERSION}"
|
57
|
+
exit
|
58
|
+
end
|
54
59
|
|
55
60
|
opts.on("-h", "--help", "Show this message") do
|
56
61
|
puts opts
|
@@ -88,7 +93,8 @@ END
|
|
88
93
|
:command => nil,
|
89
94
|
:filters => [],
|
90
95
|
:ignored => [],
|
91
|
-
:paths => []
|
96
|
+
:paths => [],
|
97
|
+
:hooks => []
|
92
98
|
}
|
93
99
|
|
94
100
|
yamopts.each do |option, argument|
|
@@ -100,6 +106,11 @@ END
|
|
100
106
|
argument = argument.split if argument.is_a? String
|
101
107
|
options[option.to_sym] += Array(argument)
|
102
108
|
|
109
|
+
when 'hooks'
|
110
|
+
argument.each do |hook|
|
111
|
+
options[:hooks] << hook
|
112
|
+
end
|
113
|
+
|
103
114
|
else
|
104
115
|
puts "Ignoring unknown option #{option}".red
|
105
116
|
end
|
data/lib/snooper.rb
CHANGED
data/lib/snooper/hook.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Author:: Will Speak (@willspeak)
|
3
|
+
# Copyright:: Copyright (c) 2013 Will Speak
|
4
|
+
# License:: Snoop is open source! See LICENCE.md for more details.
|
5
|
+
|
6
|
+
module Snooper
|
7
|
+
|
8
|
+
##
|
9
|
+
# File Change Hook
|
10
|
+
#
|
11
|
+
# Hooks represent a command that is fired when a given file changes.
|
12
|
+
class Hook
|
13
|
+
|
14
|
+
##
|
15
|
+
# Public : Create a new Hook
|
16
|
+
#
|
17
|
+
# pattern - The String or Regex to match
|
18
|
+
# command - The String containig the command to be run
|
19
|
+
#
|
20
|
+
# Returns a new Hook
|
21
|
+
def initialize(pattern, command)
|
22
|
+
raise ArgumentError, "invalid pattern" if pattern == nil
|
23
|
+
raise ArgumentError, "invalid command" if command == nil
|
24
|
+
@command = command
|
25
|
+
@pattern = to_regex pattern
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Public : Fire the hook
|
30
|
+
#
|
31
|
+
# Returns the exit code of the command
|
32
|
+
def fire
|
33
|
+
system @command
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Public : Run the Hook
|
38
|
+
#
|
39
|
+
# path - The String to match agains the hook
|
40
|
+
#
|
41
|
+
# Returns the exit code of the command or nil if the path doesn't match
|
42
|
+
def run(path)
|
43
|
+
path = Array(path)
|
44
|
+
path.each do |p|
|
45
|
+
return fire if @pattern.match p
|
46
|
+
end
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Private : Convert a string, regex, or regex-linke to Regexp
|
52
|
+
#
|
53
|
+
# regex - The String or Regexp to convert
|
54
|
+
#
|
55
|
+
# Returns a Regexp
|
56
|
+
def to_regex(regex)
|
57
|
+
Regexp.try_convert(regex) || Regexp.new(regex)
|
58
|
+
end
|
59
|
+
|
60
|
+
private :to_regex
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Author:: Will Speak (@willspeak)
|
3
|
+
# Copyright:: Copyright (c) 2013 Will Speak
|
4
|
+
# License:: Snoop is open source! See LICENCE.md for more details.
|
5
|
+
|
6
|
+
module Snooper
|
7
|
+
|
8
|
+
##
|
9
|
+
# File Change Hook
|
10
|
+
#
|
11
|
+
# Hooks represent a command that is fired when a given file changes.
|
12
|
+
|
13
|
+
class Hook
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/snooper/snoop.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
# Copyright:: Copyright (c) 2013 Will Speak
|
4
4
|
# License:: Snoop is open source! See LICENCE.md for more details.
|
5
5
|
|
6
|
+
require 'snooper/hook'
|
7
|
+
|
6
8
|
module Snooper
|
7
9
|
|
8
10
|
##
|
@@ -26,7 +28,7 @@ module Snooper
|
|
26
28
|
# [+:command+] [String] The command to run when changes are detected
|
27
29
|
|
28
30
|
def initialize(path, args = {})
|
29
|
-
to_regex = Proc.new { |r| Regexp.
|
31
|
+
to_regex = Proc.new { |r| Regexp.try_convert(r) || Regexp.new(r) }
|
30
32
|
|
31
33
|
@paths = Array(path)
|
32
34
|
@filters = args[:filters]
|
@@ -34,6 +36,20 @@ module Snooper
|
|
34
36
|
@ignored = args[:ignored]
|
35
37
|
@ignored = Array(@ignored).map(&to_regex) if @ignored
|
36
38
|
@command = args[:command]
|
39
|
+
@hooks = create_hooks(args[:hooks])
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Public : Create Hook Objects
|
44
|
+
#
|
45
|
+
# raw_hooks - The Array of maps. Each map should contain the pattern to
|
46
|
+
# match and the command to run.
|
47
|
+
#
|
48
|
+
# Returns an Array of Hook
|
49
|
+
def create_hooks(raw_hooks)
|
50
|
+
raw_hooks.to_a.map do |hook|
|
51
|
+
Hook.new hook["pattern"], hook["command"]
|
52
|
+
end
|
37
53
|
end
|
38
54
|
|
39
55
|
##
|
@@ -57,7 +73,7 @@ module Snooper
|
|
57
73
|
|
58
74
|
def on_change(modified, added, removed)
|
59
75
|
begin
|
60
|
-
# Puase the listener to
|
76
|
+
# Puase the listener to avoid spurious triggers from build output
|
61
77
|
@listener.pause if @listener
|
62
78
|
|
63
79
|
# summarise the changes made
|
@@ -68,12 +84,16 @@ module Snooper
|
|
68
84
|
statusline << ('+' * added.length).green
|
69
85
|
puts "#{statusline} #{changes.length.to_s.magenta.bold} changes"
|
70
86
|
|
87
|
+
@hooks.each do |hook|
|
88
|
+
hook.run changes
|
89
|
+
end
|
90
|
+
|
71
91
|
# run the test suite and check the result
|
72
92
|
res, time = time_command @command
|
73
93
|
if res then
|
74
|
-
puts statusbar "✓ All tests passed
|
94
|
+
puts statusbar "✓ All tests passed", time, &:white_on_green
|
75
95
|
else
|
76
|
-
puts statusbar "✗ Tests failed
|
96
|
+
puts statusbar "✗ Tests failed", time, &:white_on_red
|
77
97
|
end
|
78
98
|
|
79
99
|
# return to listening
|
@@ -93,7 +113,8 @@ module Snooper
|
|
93
113
|
#
|
94
114
|
# @param message - the message to print
|
95
115
|
|
96
|
-
def statusbar(message)
|
116
|
+
def statusbar(message, time=nil)
|
117
|
+
message << " (#{time.round(3)}s)" if time
|
97
118
|
message = message.to_s.center TermInfo.screen_width - 1
|
98
119
|
block_given? ? yield(message) : message
|
99
120
|
end
|
data/lib/snooper/version.rb
CHANGED
data/man/snooper-config.7
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
.\" generated with Ronn/v0.7.3
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.
|
4
|
-
.TH "SNOOPER\-CONFIG" "7" "
|
4
|
+
.TH "SNOOPER\-CONFIG" "7" "July 2013" "" ""
|
5
5
|
.
|
6
6
|
.SH "NAME"
|
7
7
|
\fBsnooper\-config\fR \- Configure for Espionage
|
@@ -37,6 +37,26 @@ Specifies a list of regular expressions \fIfilters\fR to use to filter the chang
|
|
37
37
|
.IP
|
38
38
|
\fINote\fR: as these are regular expressions \fB\e\.c\fR will match both \fBfoo\.c\fR and \fBbar\.cfg\fR, \fB\e\.c$\fR will only match \fB\.c\fR files\.
|
39
39
|
.
|
40
|
+
.P
|
41
|
+
Hooks
|
42
|
+
.
|
43
|
+
.P
|
44
|
+
Hooks are useful to pefrom special commads upon a subset of the file\-change events\. Each hook is run a single time if any of the filepaths that satisfy \fBfilters:\fR and \fBignored:\fR aslo match the \fBpattern:\fR of the filter\.
|
45
|
+
.
|
46
|
+
.IP "\(bu" 4
|
47
|
+
\fBhooks:\fR \fIhook_list\fR Specifies a list of hooks, where each hook represents a task that should be carried out upon a subset of the triggering events\. The hooks key should contain a list of mappings\. Each mappign should have the two following keys:
|
48
|
+
.
|
49
|
+
.IP "\(bu" 4
|
50
|
+
\fBpattern:\fR \fIregexp\fR The pattern to run the hook on\. This should be of the same format as \fBfilters:\fR and \fBignored:\fR\. Note that hooks can only match a subset of all file changes as controlled by \fBfilters:\fR and \fBignored:\fR\.
|
51
|
+
.
|
52
|
+
.IP "\(bu" 4
|
53
|
+
\fBcommand:\fR \fIcommand_string\fR A command to be run when the hook is triggered\. This is of the same format as the global \fBcommand:\fR key\.
|
54
|
+
.
|
55
|
+
.IP "" 0
|
56
|
+
|
57
|
+
.
|
58
|
+
.IP "" 0
|
59
|
+
.
|
40
60
|
.SH "SEE ALSO"
|
41
61
|
snooper(1)
|
42
62
|
.
|
data/man/snooper-config.7.html
CHANGED
@@ -126,6 +126,31 @@ testing.</p>
|
|
126
126
|
</dl>
|
127
127
|
|
128
128
|
|
129
|
+
<p>Hooks</p>
|
130
|
+
|
131
|
+
<p>Hooks are useful to pefrom special commads upon a subset of the file-change
|
132
|
+
events. Each hook is run a single time if any of the filepaths that satisfy
|
133
|
+
<code>filters:</code> and <code>ignored:</code> aslo match the <code>pattern:</code> of the filter.</p>
|
134
|
+
|
135
|
+
<ul>
|
136
|
+
<li><p><code>hooks:</code> <var>hook_list</var>
|
137
|
+
Specifies a list of hooks, where each hook represents a task that should
|
138
|
+
be carried out upon a subset of the triggering events. The hooks key should
|
139
|
+
contain a list of mappings. Each mappign should have the two following keys:</p>
|
140
|
+
|
141
|
+
<ul>
|
142
|
+
<li><p><code>pattern:</code> <var>regexp</var>
|
143
|
+
The pattern to run the hook on. This should be of the same format as
|
144
|
+
<code>filters:</code> and <code>ignored:</code>. Note that hooks can only match a subset of all
|
145
|
+
file changes as controlled by <code>filters:</code> and <code>ignored:</code>.</p></li>
|
146
|
+
<li><p><code>command:</code> <var>command_string</var>
|
147
|
+
A command to be run when the hook is triggered. This is of the same format
|
148
|
+
as the global <code>command:</code> key.</p></li>
|
149
|
+
</ul>
|
150
|
+
</li>
|
151
|
+
</ul>
|
152
|
+
|
153
|
+
|
129
154
|
<h2 id="SEE-ALSO">SEE ALSO</h2>
|
130
155
|
|
131
156
|
<p><a class="man-ref" href="snooper.1.html">snooper<span class="s">(1)</span></a></p>
|
@@ -137,7 +162,7 @@ testing.</p>
|
|
137
162
|
|
138
163
|
<ol class='man-decor man-foot man foot'>
|
139
164
|
<li class='tl'></li>
|
140
|
-
<li class='tc'>
|
165
|
+
<li class='tc'>July 2013</li>
|
141
166
|
<li class='tr'>snooper-config(7)</li>
|
142
167
|
</ol>
|
143
168
|
|
data/man/snooper-config.7.ronn
CHANGED
@@ -7,7 +7,7 @@ Configuration of `snooper` is controlled through a YAML file.
|
|
7
7
|
|
8
8
|
## FORMAT
|
9
9
|
|
10
|
-
snooper(1) expects a YAML document of key-value pairs; each pair specifies an
|
10
|
+
snooper(1) expects a YAML document of key-value pairs; each pair specifies an
|
11
11
|
option. Unknown options are ignored. Options that can contain a list of values
|
12
12
|
may also be given a single value.
|
13
13
|
|
@@ -25,8 +25,8 @@ String options
|
|
25
25
|
String Array options
|
26
26
|
|
27
27
|
* `paths:` <directories>:
|
28
|
-
Specifies a list of <directories> to watch. Directories can be either
|
29
|
-
relative or absolute paths. If no paths are specified the default is to
|
28
|
+
Specifies a list of <directories> to watch. Directories can be either
|
29
|
+
relative or absolute paths. If no paths are specified the default is to
|
30
30
|
watch `base_path`.
|
31
31
|
|
32
32
|
* `filters:` <filters>, `ignored:` <filters>:
|
@@ -38,6 +38,26 @@ String Array options
|
|
38
38
|
_Note_: as these are regular expressions `\.c` will match both
|
39
39
|
`foo.c` and `bar.cfg`, `\.c$` will only match `.c` files.
|
40
40
|
|
41
|
+
Hooks
|
42
|
+
|
43
|
+
Hooks are useful to pefrom special commads upon a subset of the file-change
|
44
|
+
events. Each hook is run a single time if any of the filepaths that satisfy
|
45
|
+
`filters:` and `ignored:` aslo match the `pattern:` of the filter.
|
46
|
+
|
47
|
+
* `hooks:` <hook_list>
|
48
|
+
Specifies a list of hooks, where each hook represents a task that should
|
49
|
+
be carried out upon a subset of the triggering events. The hooks key should
|
50
|
+
contain a list of mappings. Each mappign should have the two following keys:
|
51
|
+
|
52
|
+
* `pattern:` <regexp>
|
53
|
+
The pattern to run the hook on. This should be of the same format as
|
54
|
+
`filters:` and `ignored:`. Note that hooks can only match a subset of all
|
55
|
+
file changes as controlled by `filters:` and `ignored:`.
|
56
|
+
|
57
|
+
* `command:` <command_string>
|
58
|
+
A command to be run when the hook is triggered. This is of the same format
|
59
|
+
as the global `command:` key.
|
60
|
+
|
41
61
|
## SEE ALSO
|
42
62
|
|
43
63
|
snooper(1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snooper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Speak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06
|
11
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|
@@ -80,6 +80,8 @@ extra_rdoc_files:
|
|
80
80
|
- LICENCE.md
|
81
81
|
- README.md
|
82
82
|
files:
|
83
|
+
- lib/snooper/hook.rb
|
84
|
+
- lib/snooper/hook.rb~
|
83
85
|
- lib/snooper/snoop.rb
|
84
86
|
- lib/snooper/version.rb
|
85
87
|
- lib/snooper.rb
|