guard 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +348 -330
- data/LICENSE +19 -19
- data/README.md +464 -431
- data/bin/guard +6 -6
- data/lib/guard.rb +452 -414
- data/lib/guard/cli.rb +119 -178
- data/lib/guard/dsl.rb +370 -370
- data/lib/guard/dsl_describer.rb +150 -60
- data/lib/guard/group.rb +37 -37
- data/lib/guard/guard.rb +129 -113
- data/lib/guard/hook.rb +118 -118
- data/lib/guard/interactor.rb +110 -44
- data/lib/guard/listener.rb +350 -350
- data/lib/guard/listeners/darwin.rb +66 -66
- data/lib/guard/listeners/linux.rb +97 -97
- data/lib/guard/listeners/polling.rb +55 -55
- data/lib/guard/listeners/windows.rb +61 -61
- data/lib/guard/notifier.rb +290 -211
- data/lib/guard/templates/Guardfile +2 -2
- data/lib/guard/ui.rb +193 -188
- data/lib/guard/version.rb +6 -6
- data/lib/guard/watcher.rb +114 -110
- data/man/guard.1 +93 -93
- data/man/guard.1.html +176 -176
- metadata +107 -59
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2011 Thibaud Guillaume-Gentil
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2011 Thibaud Guillaume-Gentil
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,431 +1,464 @@
|
|
1
|
-
Guard [![Build Status](https://secure.travis-ci.org/guard/guard.png)](http://travis-ci.org/guard/guard)
|
2
|
-
=====
|
3
|
-
|
4
|
-
Guard is a command line tool that easily handle events on files modifications.
|
5
|
-
|
6
|
-
If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
|
7
|
-
|
8
|
-
Features
|
9
|
-
--------
|
10
|
-
|
11
|
-
* [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support on Mac OS X 10.5+ (without RubyCocoa!, [rb-fsevent gem, >= 0.3.5](https://rubygems.org/gems/rb-fsevent) required).
|
12
|
-
* [Inotify](http://en.wikipedia.org/wiki/Inotify) support on Linux ([rb-inotify gem, >= 0.5.1](https://rubygems.org/gems/rb-inotify) required).
|
13
|
-
* [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support on Windows ([rb-fchange, >= 0.0.2](https://rubygems.org/gems/rb-fchange) required).
|
14
|
-
* Polling on the other operating systems (help us to support more OS).
|
15
|
-
* Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected).
|
16
|
-
* Visual notifications on Mac OSX ([Growl](http://growl.info)), Linux ([Libnotify](http://developer.gnome.org/libnotify)) and Windows ([Notifu](http://www.paralint.com/projects/notifu)).
|
17
|
-
* Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
|
18
|
-
|
19
|
-
Screencast
|
20
|
-
----------
|
21
|
-
|
22
|
-
Ryan Bates made a Railscast on Guard, you can view it here: http://railscasts.com/episodes/264-guard
|
23
|
-
|
24
|
-
Install
|
25
|
-
-------
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
$ gem install
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
$
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
gem 'rb-
|
88
|
-
gem '
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Install the [
|
97
|
-
|
98
|
-
$ gem install
|
99
|
-
|
100
|
-
Install the [
|
101
|
-
|
102
|
-
$ gem install
|
103
|
-
|
104
|
-
And add them to your Gemfile:
|
105
|
-
|
106
|
-
gem 'rb-
|
107
|
-
gem '
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
$
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
$
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
### `-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
$ guard --
|
168
|
-
$ guard -
|
169
|
-
|
170
|
-
### `-
|
171
|
-
|
172
|
-
Guard can
|
173
|
-
|
174
|
-
|
175
|
-
$ guard
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
$ guard
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
*
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
*
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
#
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
def
|
397
|
-
end
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
1
|
+
Guard [![Build Status](https://secure.travis-ci.org/guard/guard.png)](http://travis-ci.org/guard/guard)
|
2
|
+
=====
|
3
|
+
|
4
|
+
Guard is a command line tool that easily handle events on files modifications.
|
5
|
+
|
6
|
+
If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
|
7
|
+
|
8
|
+
Features
|
9
|
+
--------
|
10
|
+
|
11
|
+
* [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support on Mac OS X 10.5+ (without RubyCocoa!, [rb-fsevent gem, >= 0.3.5](https://rubygems.org/gems/rb-fsevent) required).
|
12
|
+
* [Inotify](http://en.wikipedia.org/wiki/Inotify) support on Linux ([rb-inotify gem, >= 0.5.1](https://rubygems.org/gems/rb-inotify) required).
|
13
|
+
* [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support on Windows ([rb-fchange, >= 0.0.2](https://rubygems.org/gems/rb-fchange) required).
|
14
|
+
* Polling on the other operating systems (help us to support more OS).
|
15
|
+
* Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected).
|
16
|
+
* Visual notifications on Mac OSX ([Growl](http://growl.info)), Linux ([Libnotify](http://developer.gnome.org/libnotify)) and Windows ([Notifu](http://www.paralint.com/projects/notifu)).
|
17
|
+
* Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
|
18
|
+
|
19
|
+
Screencast
|
20
|
+
----------
|
21
|
+
|
22
|
+
Ryan Bates made a Railscast on Guard, you can view it here: [http://railscasts.com/episodes/264-guard](http://railscasts.com/episodes/264-guard)
|
23
|
+
|
24
|
+
Install
|
25
|
+
-------
|
26
|
+
|
27
|
+
Add Guard to your `Gemfile`:
|
28
|
+
|
29
|
+
group :development do
|
30
|
+
gem 'guard'
|
31
|
+
gem 'rb-inotify', :require => false
|
32
|
+
gem 'rb-fsevent', :require => false
|
33
|
+
gem 'rb-fchange', :require => false
|
34
|
+
end
|
35
|
+
|
36
|
+
and install it via Bundler:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
Generate an empty Guardfile with:
|
41
|
+
|
42
|
+
$ guard init
|
43
|
+
|
44
|
+
You may optionally place a .Guardfile in your home directory to use it across multiple projects.
|
45
|
+
Also note that if a `.guard.rb` is found in your home directory, it will be appended to the Guardfile.
|
46
|
+
|
47
|
+
Add the guards you need to your Guardfile (see the existing guards below).
|
48
|
+
|
49
|
+
Now, be sure to read the particular instructions for your operating system: [Mac OS X](#mac) | [Linux](#linux) | [Windows](#win)
|
50
|
+
|
51
|
+
<a name="mac" />
|
52
|
+
|
53
|
+
### On Mac OS X
|
54
|
+
|
55
|
+
Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support:
|
56
|
+
|
57
|
+
$ gem install rb-fsevent
|
58
|
+
|
59
|
+
You have three possibilities for getting Growl support:
|
60
|
+
|
61
|
+
Use the [growl_notify gem](https://rubygems.org/gems/growl_notify):
|
62
|
+
|
63
|
+
$ gem install growl_notify
|
64
|
+
|
65
|
+
The `growl_notify` gem is compatible with Growl >= 1.3 and uses AppleScript to send Growl notifications.
|
66
|
+
The gem needs a native C extension to make use of AppleScript and does not run on JRuby and MacRuby.
|
67
|
+
|
68
|
+
Use the [ruby_gntp gem](https://github.com/snaka/ruby_gntp):
|
69
|
+
|
70
|
+
$ gem install ruby_gntp
|
71
|
+
|
72
|
+
The `ruby_gntp` gem is compatible with Growl >= 1.3 and uses the Growl Notification Transport Protocol to send Growl
|
73
|
+
notifications. Guard supports multiple notification channels for customizing each notification type, but it's limited
|
74
|
+
to the local host currently.
|
75
|
+
|
76
|
+
Use the [growl gem](https://rubygems.org/gems/growl):
|
77
|
+
|
78
|
+
$ gem install growl
|
79
|
+
|
80
|
+
The `growl` gem is compatible with all versions of Growl and uses a command line tool [growlnotify](http://growl.info/extras.php#growlnotify)
|
81
|
+
that must be separately downloaded and installed. You can also install it with HomeBrew:
|
82
|
+
|
83
|
+
$ brew install growlnotify
|
84
|
+
|
85
|
+
Finally you have to add your Growl library of choice to your Gemfile:
|
86
|
+
|
87
|
+
gem 'rb-fsevent'
|
88
|
+
gem 'growl_notify' # or gem 'ruby_gntp' or gem 'growl'
|
89
|
+
|
90
|
+
Have a look at the [Guard Wiki](https://github.com/guard/guard/wiki/Which-Growl-library-should-I-use) for more information.
|
91
|
+
|
92
|
+
<a name="linux" />
|
93
|
+
|
94
|
+
### On Linux
|
95
|
+
|
96
|
+
Install the [rb-inotify gem](https://rubygems.org/gems/rb-inotify) for [inotify](http://en.wikipedia.org/wiki/Inotify) support:
|
97
|
+
|
98
|
+
$ gem install rb-inotify
|
99
|
+
|
100
|
+
Install the [libnotify gem](https://rubygems.org/gems/libnotify) if you want visual notification support:
|
101
|
+
|
102
|
+
$ gem install libnotify
|
103
|
+
|
104
|
+
And add them to your Gemfile:
|
105
|
+
|
106
|
+
gem 'rb-inotify'
|
107
|
+
gem 'libnotify'
|
108
|
+
|
109
|
+
<a name="win" />
|
110
|
+
|
111
|
+
### On Windows
|
112
|
+
|
113
|
+
Install the [rb-fchange gem](https://rubygems.org/gems/rb-fchange) for [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support:
|
114
|
+
|
115
|
+
$ gem install rb-fchange
|
116
|
+
|
117
|
+
Install the [win32console gem](https://rubygems.org/gems/win32console) if you want colors in your terminal:
|
118
|
+
|
119
|
+
$ gem install win32console
|
120
|
+
|
121
|
+
Install the [rb-notifu gem](https://rubygems.org/gems/rb-notifu) if you want visual notification support:
|
122
|
+
|
123
|
+
$ gem install rb-notifu
|
124
|
+
|
125
|
+
And add them to your Gemfile:
|
126
|
+
|
127
|
+
gem 'rb-fchange'
|
128
|
+
gem 'rb-notifu'
|
129
|
+
gem 'win32console'
|
130
|
+
|
131
|
+
Usage
|
132
|
+
-----
|
133
|
+
|
134
|
+
Just launch Guard inside your Ruby / Rails project with:
|
135
|
+
|
136
|
+
$ guard [start]
|
137
|
+
|
138
|
+
or if you use Bundler, to run the Guard executable specific to your bundle:
|
139
|
+
|
140
|
+
$ bundle exec guard [start]
|
141
|
+
|
142
|
+
Guard will look for a Guardfile in your current directory. If it does not find one, it will look in your `$HOME` directory for a .Guardfile.
|
143
|
+
|
144
|
+
Command line options
|
145
|
+
--------------------
|
146
|
+
|
147
|
+
### `-c`/`--clear` option
|
148
|
+
|
149
|
+
Shell can be cleared after each change:
|
150
|
+
|
151
|
+
$ guard --clear
|
152
|
+
$ guard -c # shortcut
|
153
|
+
|
154
|
+
### `-n`/`--notify` option
|
155
|
+
|
156
|
+
Notifications (growl/libnotify) can be disabled:
|
157
|
+
|
158
|
+
$ guard --notify false
|
159
|
+
$ guard -n f # shortcut
|
160
|
+
|
161
|
+
Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
|
162
|
+
|
163
|
+
### `-g`/`--group` option
|
164
|
+
|
165
|
+
Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
|
166
|
+
|
167
|
+
$ guard --group group_name another_group_name
|
168
|
+
$ guard -g group_name another_group_name # shortcut
|
169
|
+
|
170
|
+
### `-d`/`--debug` option
|
171
|
+
|
172
|
+
Guard can be run in debug mode:
|
173
|
+
|
174
|
+
$ guard --debug
|
175
|
+
$ guard -d # shortcut
|
176
|
+
|
177
|
+
### `-w`/`--watchdir` option
|
178
|
+
|
179
|
+
Guard can watch in any directory (instead of the current directory):
|
180
|
+
|
181
|
+
$ guard --watchdir ~/your/fancy/project
|
182
|
+
$ guard -w ~/your/fancy/project # shortcut
|
183
|
+
|
184
|
+
### `-G`/`--guardfile` option
|
185
|
+
|
186
|
+
Guard can use a Guardfile not located in the current directory:
|
187
|
+
|
188
|
+
$ guard --guardfile ~/.your_global_guardfile
|
189
|
+
$ guard -G ~/.your_global_guardfile # shortcut
|
190
|
+
|
191
|
+
### `-A`/`--watch-all-modifications` option
|
192
|
+
|
193
|
+
Guard can optionally watch all file modifications like moves or deletions with:
|
194
|
+
|
195
|
+
$ guard start -A
|
196
|
+
$ guard start --watch-all-modifications
|
197
|
+
|
198
|
+
### `-i`/`--no-interactions` option
|
199
|
+
|
200
|
+
Turn off completely any Guard terminal [interactions](#interactions) with:
|
201
|
+
|
202
|
+
$ guard start -A
|
203
|
+
$ guard start --watch-all-modifications
|
204
|
+
|
205
|
+
An exhaustive list of options is available with:
|
206
|
+
|
207
|
+
$ guard help [TASK]
|
208
|
+
|
209
|
+
<a name="interactions" />
|
210
|
+
|
211
|
+
Interactions
|
212
|
+
------------
|
213
|
+
|
214
|
+
**From version >= 0.7.0 Posix Signal handlers are no more used to interact with Guard. If you're using a version < 0.7, please refer to the [README in the v0.6 branch](https://github.com/guard/guard/blob/v0.6/README.md).**
|
215
|
+
|
216
|
+
When Guard do nothing you can interact with by entering a command + hitting return/enter:
|
217
|
+
|
218
|
+
* `stop`: `stop|quit|exit|s|q|e + return` - Calls each guard's `#stop` method, in the same order they are declared in the Guardfile, and then quits Guard itself.
|
219
|
+
* `reload`: `reload|r|z + return` - Calls each guard's `#reload` method, in the same order they are declared in the Guardfile.
|
220
|
+
* `pause`: `pause|p + return` - Toggle files modification listening. Useful when switching git branches.
|
221
|
+
* `run_all`: `just return (no commands)` - Calls each guard's `#run_all` method, in the same order they are declared in the Guardfile.
|
222
|
+
|
223
|
+
`reload` and `run_all` actions can be scoped to only run on a certain guard or group. Examples:
|
224
|
+
|
225
|
+
* `backend reload + return` - Call only each guard's `#reload` method on backend group.
|
226
|
+
* `rspec + return` - Call only rspec guard's `#run_all` method.
|
227
|
+
|
228
|
+
Available Guards
|
229
|
+
----------------
|
230
|
+
|
231
|
+
A list of the available guards is present [in the wiki](https://github.com/guard/guard/wiki/List-of-available-Guards).
|
232
|
+
|
233
|
+
### Add a guard to your Guardfile
|
234
|
+
|
235
|
+
Add it to your Gemfile (inside the `development` group):
|
236
|
+
|
237
|
+
gem '<guard-name>'
|
238
|
+
|
239
|
+
You can list all guards installed on your system with:
|
240
|
+
|
241
|
+
$ guard list
|
242
|
+
|
243
|
+
Insert default guard's definition to your Guardfile by running this command:
|
244
|
+
|
245
|
+
$ guard init <guard-name>
|
246
|
+
|
247
|
+
You are good to go, or you can modify your guards' definition to suit your needs.
|
248
|
+
|
249
|
+
Guardfile DSL
|
250
|
+
-------------
|
251
|
+
|
252
|
+
The Guardfile DSL consists of the following methods:
|
253
|
+
|
254
|
+
* `#guard` - Allows you to add a guard with an optional hash of options.
|
255
|
+
* `#watch` - Allows you to define which files are supervised by a guard. An optional block can be added to overwrite the paths sent to the guard's `#run_on_change` method or to launch any arbitrary command.
|
256
|
+
* `#group` - Allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part. Guards that don't belong to a group are considered global and are always run.
|
257
|
+
* `#callback` - Allows you to execute arbitrary code before or after any of the `start`, `stop`, `reload`, `run_all` and `run_on_change` guards' method. You can even insert more hooks inside these methods. Please [checkout the Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for more details.
|
258
|
+
* `#ignore_paths` - Allows you to ignore top level directories altogether. This comes is handy when you have large amounts of non-source data in you project. By default .bundle, .git, log, tmp, and vendor are ignored. Currently it is only possible to ignore the immediate descendants of the watched directory.
|
259
|
+
|
260
|
+
Example:
|
261
|
+
|
262
|
+
ignore_paths 'foo', 'bar'
|
263
|
+
|
264
|
+
group 'backend' do
|
265
|
+
guard 'bundler' do
|
266
|
+
watch('Gemfile')
|
267
|
+
end
|
268
|
+
|
269
|
+
guard 'rspec', :cli => '--color --format doc' do
|
270
|
+
# Regexp watch patterns are matched with Regexp#match
|
271
|
+
watch(%r{^spec/.+_spec\.rb$})
|
272
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
273
|
+
watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
|
274
|
+
watch(%r{^spec/.+\.rb$}) { `say hello` }
|
275
|
+
|
276
|
+
# String watch patterns are matched with simple '=='
|
277
|
+
watch('spec/spec_helper.rb') { "spec" }
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
group 'frontend' do
|
282
|
+
guard 'coffeescript', :output => 'public/javascripts/compiled' do
|
283
|
+
watch(%r{^app/coffeescripts/.+\.coffee$})
|
284
|
+
end
|
285
|
+
|
286
|
+
guard 'livereload' do
|
287
|
+
watch(%r{^app/.+\.(erb|haml)$})
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
Using a Guardfile without the `guard` binary
|
292
|
+
--------------------------------------------
|
293
|
+
|
294
|
+
The Guardfile DSL can also be used in a programmatic fashion by calling directly `Guard::Dsl.evaluate_guardfile`.
|
295
|
+
Available options are as follow:
|
296
|
+
|
297
|
+
* `:guardfile` - The path to a valid Guardfile.
|
298
|
+
* `:guardfile_contents` - A string representing the content of a valid Guardfile
|
299
|
+
|
300
|
+
Remember, without any options given, Guard will look for a Guardfile in your current directory and if it does not find one, it will look for it in your `$HOME` directory.
|
301
|
+
|
302
|
+
For instance, you could use it as follow:
|
303
|
+
|
304
|
+
gem 'guard'
|
305
|
+
require 'guard'
|
306
|
+
|
307
|
+
Guard.setup
|
308
|
+
|
309
|
+
Guard::Dsl.evaluate_guardfile(:guardfile => '/your/custom/path/to/a/valid/Guardfile')
|
310
|
+
# or
|
311
|
+
Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
|
312
|
+
guard 'rspec' do
|
313
|
+
watch(%r{^spec/.+_spec\.rb$})
|
314
|
+
end
|
315
|
+
")
|
316
|
+
|
317
|
+
### Listing defined guards/groups for the current project
|
318
|
+
|
319
|
+
You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
|
320
|
+
|
321
|
+
$ guard -T
|
322
|
+
|
323
|
+
(global):
|
324
|
+
shell
|
325
|
+
Group backend:
|
326
|
+
bundler
|
327
|
+
rspec: cli => "--color --format doc"
|
328
|
+
Group frontend:
|
329
|
+
coffeescript: output => "public/javascripts/compiled"
|
330
|
+
livereload
|
331
|
+
|
332
|
+
User config file
|
333
|
+
----------------
|
334
|
+
|
335
|
+
If a `.guard.rb` is found in your home directory, it will be appended to
|
336
|
+
the Guardfile. This can be used for tasks you want guard to handle but
|
337
|
+
other users probably don't. For example, indexing your source tree with
|
338
|
+
[Ctags](http://ctags.sourceforge.net):
|
339
|
+
|
340
|
+
guard 'shell' do
|
341
|
+
watch(%r{^(?:app|lib)/.+\.rb$}) { `ctags -R` }
|
342
|
+
end
|
343
|
+
|
344
|
+
Create a new guard
|
345
|
+
------------------
|
346
|
+
|
347
|
+
Creating a new guard is very easy, just create a new gem (`bundle gem` if you use Bundler) with this basic structure:
|
348
|
+
|
349
|
+
.travis.yml # bonus point!
|
350
|
+
CHANGELOG.md # bonus point!
|
351
|
+
Gemfile
|
352
|
+
guard-name.gemspec
|
353
|
+
Guardfile
|
354
|
+
lib/
|
355
|
+
guard/
|
356
|
+
guard-name/
|
357
|
+
templates/
|
358
|
+
Guardfile # needed for `guard init <guard-name>`
|
359
|
+
version.rb
|
360
|
+
guard-name.rb
|
361
|
+
test/ # or spec/
|
362
|
+
README.md
|
363
|
+
|
364
|
+
`Guard::GuardName` (in `lib/guard/guard-name.rb`) must inherit from
|
365
|
+
[Guard::Guard](http://rubydoc.info/github/guard/guard/master/Guard/Guard) and should overwrite at least one of
|
366
|
+
the basic `Guard::Guard` task methods.
|
367
|
+
|
368
|
+
Here is an example scaffold for `lib/guard/guard-name.rb`:
|
369
|
+
|
370
|
+
require 'guard'
|
371
|
+
require 'guard/guard'
|
372
|
+
|
373
|
+
module Guard
|
374
|
+
class GuardName < Guard
|
375
|
+
|
376
|
+
# Initialize a Guard.
|
377
|
+
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
378
|
+
# @param [Hash] options the custom Guard options
|
379
|
+
def initialize(watchers = [], options = {})
|
380
|
+
super
|
381
|
+
end
|
382
|
+
|
383
|
+
# Call once when Guard starts. Please override initialize method to init stuff.
|
384
|
+
# @raise [:task_has_failed] when start has failed
|
385
|
+
def start
|
386
|
+
end
|
387
|
+
|
388
|
+
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
389
|
+
# @raise [:task_has_failed] when stop has failed
|
390
|
+
def stop
|
391
|
+
end
|
392
|
+
|
393
|
+
# Called when `reload|r|z + enter` is pressed.
|
394
|
+
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
395
|
+
# @raise [:task_has_failed] when reload has failed
|
396
|
+
def reload
|
397
|
+
end
|
398
|
+
|
399
|
+
# Called when just `enter` is pressed
|
400
|
+
# This method should be principally used for long action like running all specs/tests/...
|
401
|
+
# @raise [:task_has_failed] when run_all has failed
|
402
|
+
def run_all
|
403
|
+
end
|
404
|
+
|
405
|
+
# Called on file(s) modifications that the Guard watches.
|
406
|
+
# @param [Array<String>] paths the changes files or paths
|
407
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
408
|
+
def run_on_change(paths)
|
409
|
+
end
|
410
|
+
|
411
|
+
# Called on file(s) deletions that the Guard watches.
|
412
|
+
# @param [Array<String>] paths the deleted files or paths
|
413
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
414
|
+
def run_on_deletion(paths)
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
Please take a look at the [existing guards' source code](https://github.com/guard/guard/wiki/List-of-available-Guards)
|
421
|
+
for more concrete example and inspiration.
|
422
|
+
|
423
|
+
Alternatively, a new guard can be added inline to a Guardfile with this basic structure:
|
424
|
+
|
425
|
+
require 'guard/guard'
|
426
|
+
|
427
|
+
module ::Guard
|
428
|
+
class InlineGuard < ::Guard::Guard
|
429
|
+
def run_all
|
430
|
+
end
|
431
|
+
|
432
|
+
def run_on_change(paths)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
Here is a very cool example by [@avdi](https://github.com/avdi) : [http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis](http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis)
|
438
|
+
|
439
|
+
Development
|
440
|
+
-----------
|
441
|
+
|
442
|
+
* Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard/master/frames).
|
443
|
+
* Source hosted at [GitHub](https://github.com/guard/guard).
|
444
|
+
* Report issues and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
|
445
|
+
|
446
|
+
Pull requests are very welcome! Please try to follow these simple "rules", though:
|
447
|
+
|
448
|
+
- Please create a topic branch for every separate change you make;
|
449
|
+
- Make sure your patches are well tested;
|
450
|
+
- Update the README (if applicable);
|
451
|
+
- Update the CHANGELOG (maybe not for a typo but don't hesitate!);
|
452
|
+
- Please **do not change** the version number.
|
453
|
+
|
454
|
+
For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
|
455
|
+
|
456
|
+
Author
|
457
|
+
------
|
458
|
+
|
459
|
+
[Thibaud Guillaume-Gentil](https://github.com/thibaudgg)
|
460
|
+
|
461
|
+
Contributors
|
462
|
+
------------
|
463
|
+
|
464
|
+
[https://github.com/guard/guard/contributors](https://github.com/guard/guard/contributors)
|