guard 2.6.1 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -58
  3. data/bin/guard +2 -2
  4. data/lib/guard.rb +64 -59
  5. data/lib/guard/cli.rb +66 -60
  6. data/lib/guard/cli.rb.orig +215 -0
  7. data/lib/guard/commander.rb +45 -69
  8. data/lib/guard/commands/all.rb +21 -19
  9. data/lib/guard/commands/change.rb +17 -22
  10. data/lib/guard/commands/notification.rb +15 -16
  11. data/lib/guard/commands/pause.rb +14 -15
  12. data/lib/guard/commands/reload.rb +19 -20
  13. data/lib/guard/commands/scope.rb +23 -19
  14. data/lib/guard/commands/show.rb +13 -16
  15. data/lib/guard/deprecated_methods.rb +6 -10
  16. data/lib/guard/deprecator.rb +52 -37
  17. data/lib/guard/dsl.rb +55 -33
  18. data/lib/guard/dsl_describer.rb +83 -31
  19. data/lib/guard/dsl_describer.rb.orig +184 -0
  20. data/lib/guard/group.rb +7 -6
  21. data/lib/guard/guard.rb +4 -4
  22. data/lib/guard/guard.rb.orig +42 -0
  23. data/lib/guard/guardfile.rb +12 -13
  24. data/lib/guard/guardfile/evaluator.rb +77 -55
  25. data/lib/guard/guardfile/evaluator.rb.orig +275 -0
  26. data/lib/guard/guardfile/generator.rb +25 -20
  27. data/lib/guard/interactor.rb +52 -293
  28. data/lib/guard/interactor.rb.orig +85 -0
  29. data/lib/guard/jobs/base.rb +21 -0
  30. data/lib/guard/jobs/pry_wrapper.rb +290 -0
  31. data/lib/guard/jobs/pry_wrapper.rb.orig +293 -0
  32. data/lib/guard/jobs/sleep.rb +25 -0
  33. data/lib/guard/notifier.rb +42 -39
  34. data/lib/guard/notifiers/base.rb +25 -24
  35. data/lib/guard/notifiers/emacs.rb +30 -24
  36. data/lib/guard/notifiers/file_notifier.rb +3 -7
  37. data/lib/guard/notifiers/gntp.rb +22 -22
  38. data/lib/guard/notifiers/growl.rb +16 -15
  39. data/lib/guard/notifiers/libnotify.rb +7 -10
  40. data/lib/guard/notifiers/notifysend.rb +15 -14
  41. data/lib/guard/notifiers/rb_notifu.rb +8 -10
  42. data/lib/guard/notifiers/terminal_notifier.rb +15 -11
  43. data/lib/guard/notifiers/terminal_title.rb +4 -8
  44. data/lib/guard/notifiers/tmux.rb +104 -71
  45. data/lib/guard/options.rb +1 -5
  46. data/lib/guard/plugin.rb +1 -3
  47. data/lib/guard/plugin/base.rb +12 -9
  48. data/lib/guard/plugin/hooker.rb +1 -5
  49. data/lib/guard/plugin_util.rb +46 -25
  50. data/lib/guard/plugin_util.rb.orig +178 -0
  51. data/lib/guard/rake_task.rb +4 -7
  52. data/lib/guard/reevaluator.rb +13 -0
  53. data/lib/guard/runner.rb +50 -78
  54. data/lib/guard/runner.rb.orig +200 -0
  55. data/lib/guard/setuper.rb +199 -130
  56. data/lib/guard/setuper.rb.orig +348 -0
  57. data/lib/guard/sheller.rb +107 -0
  58. data/lib/guard/tags +367 -0
  59. data/lib/guard/ui.rb +50 -38
  60. data/lib/guard/ui.rb.orig +254 -0
  61. data/lib/guard/ui/colors.rb +17 -21
  62. data/lib/guard/version.rb +1 -1
  63. data/lib/guard/version.rb.orig +3 -0
  64. data/lib/guard/watcher.rb +49 -62
  65. metadata +21 -4
  66. data/lib/guard/notifiers/growl_notify.rb +0 -93
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0397104f7cae5c27eb8622dce9e0bc6ed87aee5
4
- data.tar.gz: cd203c2e48e94275ea4216ae408ff674a6585175
3
+ metadata.gz: f713c5e30ef7f2814a804f5fafdb58979caa6619
4
+ data.tar.gz: ce94c3678722ee2d4d6ddfca527d5d598fffa069
5
5
  SHA512:
6
- metadata.gz: ccfc1e22709ef26e1c904956c9925058fac6d791ea9123dabbde1df189f0de9fda9b38bb87ac7ac3db36ed4bd93b8ec6f8ea4fe371e7e0efbd6b81dfb5559089
7
- data.tar.gz: d7aeedb746d432f07b701c70e78814e445e4800d2ca0b59692ed4f652f6659022589a06627f0424ff1c0697dd280ddcb0433233ad216aa5270f97022eddd963b
6
+ metadata.gz: 3fdcb3cad5b86d6b36d570c4c534742ad9613e164c660c6de608a38771afd5f776a6cbc2e2a81bbc43330058175a9ee73c86a8b76766cdb6918df3b60f434cc2
7
+ data.tar.gz: 9ff385cce046e434c8a2b577915e58453793dce6b6aa08fccc20bf293421ba862872d7df0c80e37737c5e7bceed972ea4e26c87c11c2f2a80086c6c95a01fc8c
data/README.md CHANGED
@@ -1,12 +1,19 @@
1
+ ### :warning: Guard is [looking for new maintainers](https://groups.google.com/forum/#!topic/guard-dev/2Td0QTvTIsE). Please [contact me](mailto:thibaud@thibaud.gg) if you're interested.
2
+
1
3
  Guard
2
4
  =====
3
5
 
4
- [![Gem Version](https://badge.fury.io/rb/guard.png)](http://badge.fury.io/rb/guard) [![Build Status](https://travis-ci.org/guard/guard.png?branch=master)](https://travis-ci.org/guard/guard) [![Dependency Status](https://gemnasium.com/guard/guard.png)](https://gemnasium.com/guard/guard) [![Code Climate](https://codeclimate.com/github/guard/guard.png)](https://codeclimate.com/github/guard/guard) [![Coverage Status](https://coveralls.io/repos/guard/guard/badge.png?branch=master)](https://coveralls.io/r/guard/guard) [![Inline docs](http://inch-pages.github.io/github/guard/guard.png)](http://inch-pages.github.io/github/guard/guard)
6
+ [![Gem Version](https://badge.fury.io/rb/guard.png)](http://badge.fury.io/rb/guard) [![Build Status](https://travis-ci.org/guard/guard.png?branch=master)](https://travis-ci.org/guard/guard) [![Dependency Status](https://gemnasium.com/guard/guard.png)](https://gemnasium.com/guard/guard) [![Code Climate](https://codeclimate.com/github/guard/guard.png)](https://codeclimate.com/github/guard/guard) [![Coverage Status](https://coveralls.io/repos/guard/guard/badge.png?branch=master)](https://coveralls.io/r/guard/guard) [![Inline docs](http://inch-ci.org/github/guard/guard.png)](http://inch-ci.org/github/guard/guard)
5
7
 
6
8
  <img src="http://cl.ly/image/1k3o1r2Z3a0J/guard-Icon.png" alt="Guard Icon" align="right" />
7
9
  Guard is a command line tool to easily handle events on file system modifications.
8
10
 
9
- This document contains a lot of information, please take your time and read these instructions carefully. If you have
11
+ Guard has many very handy features, so read this document through at least once
12
+ to be aware of them - or you'll likely miss out on really cool ideas and tricks.
13
+
14
+ Also, by reading through you'll likely avoid common and time-consuming problems which Guard simply can't automatically solve.
15
+
16
+ If you have
10
17
  any questions about the Guard usage or want to share some information with the Guard community, please go to one of
11
18
  the following places:
12
19
 
@@ -65,11 +72,31 @@ Run Guard through Bundler with:
65
72
  $ bundle exec guard
66
73
  ```
67
74
 
68
- **It's important that you always run Guard through Bundler to avoid errors.** If you're getting sick of typing
69
- `bundle exec` all the time, try the [Rubygems Bundler](https://github.com/mpapis/rubygems-bundler).
75
+ If you are on Mac OS X and have problems with either Guard not reacting to file
76
+ changes or Pry behaving strange, then you should [add proper Readline support
77
+ to Ruby on Mac OS
78
+ X](https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X).
79
+
80
+
81
+ #### Avoiding gem/dependency problems
82
+
83
+ **It's important that you always run Guard through Bundler to avoid errors.**
84
+
85
+ If you're getting sick of typing `bundle exec` all the time, try one of the following:
86
+
87
+ * (Recommended) Running `bundle binstub guard` will create `bin/guard` in your
88
+ project, which means running `bin/guard` (tab completion will save you a key
89
+ stroke or two) will have the exact same result as `bundle exec guard`
90
+
91
+ * Or, for RubyGems >= 2.2.0 (at least, though the more recent the better),
92
+ simply set the `RUBYGEMS_GEMDEPS` environment variable to `-` (for autodetecting
93
+ the Gemfile in the current or parent directories) or set it to the path of your Gemfile.
70
94
 
71
- If you are on Mac OS X and have problems with either Guard not reacting to file changes or Pry behaving strange, then
72
- you should [add proper Readline support to Ruby on Mac OS X](https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X).
95
+ (To upgrade RubyGems from RVM, use the `rvm rubygems` command).
96
+
97
+ *NOTE: this Rubygems feature is still under development still lacks many features of bundler*
98
+
99
+ * Or, for RubyGems < 2.2.0 check out the [Rubygems Bundler](https://github.com/mpapis/rubygems-bundler).
73
100
 
74
101
  #### Add Guard plugins
75
102
 
@@ -210,8 +237,8 @@ $ bundle exec guard -P plugin_name another_plugin_name # shortcut
210
237
 
211
238
  #### `-d`/`--debug` option
212
239
 
213
- Guard can display debug information which can be very usefull for plugins
214
- developers with:
240
+ Guard can display debug information (useful for plugin
241
+ developers) with:
215
242
 
216
243
  ```bash
217
244
  $ bundle exec guard --debug
@@ -223,10 +250,18 @@ $ bundle exec guard -d # shortcut
223
250
  Guard can watch any number of directories instead of only the current directory:
224
251
 
225
252
  ```bash
226
- $ bundle exec guard --watchdir ~/your/fancy/project
227
- $ bundle exec guard -w ~/your/fancy/project ~/your/fancier/project2 #multiple directories
228
- $ bundle exec guard -w ~/your/fancy/project # shortcut
253
+ $ bundle exec guard --watchdir source/files # watch a subdirectory of your project
254
+ $ bundle exec guard -w source/files # shortcut
255
+ $ bundle exec guard -w sources/foo assets/foo ./config # multiple directories
256
+
257
+ $ bundle exec guard -w /fancy/project # path outside project - watch out! (see below)
229
258
  ```
259
+ *NOTE: this option is only meant for ignoring subdirectories in the CURRENT
260
+ directory - by selecting which ones to actually track.*
261
+
262
+ If your watched directories are outside the current one, or if `--watchdirs` isn't working
263
+ as you expect, be sure to read: [Correctly using watchdirs](https://github.com/guard/guard/wiki/Correctly-using-the---watchdir-option)
264
+
230
265
 
231
266
  #### `-G`/`--guardfile` option
232
267
 
@@ -236,6 +271,7 @@ Guard can use a `Guardfile` not located in the current directory:
236
271
  $ bundle exec guard --guardfile ~/.your_global_guardfile
237
272
  $ bundle exec guard -G ~/.your_global_guardfile # shortcut
238
273
  ```
274
+ *TIP: set `BUNDLER_GEMFILE` environment variable to point to your Gemfile if it isn't in the current directory or the current Gemfile doesn't include all your favorite plugins*
239
275
 
240
276
  #### `-i`/`--no-interactions` option
241
277
 
@@ -259,6 +295,8 @@ $ bundle exec guard start --no-bundler-warning
259
295
 
260
296
  Turn on deprecation warnings.
261
297
 
298
+ *NOTE: They are OFF by default (see: [#298](https://github.com/guard/guard/issues/298))*
299
+
262
300
  #### `-l`/`--latency` option
263
301
 
264
302
  Overwrite Listen's default latency, useful when your hard-drive / system is slow.
@@ -268,6 +306,13 @@ $ bundle exec guard start -l 1.5
268
306
  $ bundle exec guard start --latency 1.5
269
307
  ```
270
308
 
309
+ *NOTE: this option is OS specific: while higher values may reduce CPU usage
310
+ (and lower values may increase responsiveness) when in polling mode , it has no
311
+ effect for optimized backends (except on Mac OS). If guard is not behaving as
312
+ you want, you'll likely instead want to tweak the `--wait-for-delay` option
313
+ below or use the `--watchdirs` option.*
314
+
315
+
271
316
  #### `-p`/`--force-polling` option
272
317
 
273
318
  Force Listen polling listener usage.
@@ -279,7 +324,8 @@ $ bundle exec guard start --force-polling
279
324
 
280
325
  #### `-y`/`--wait-for-delay` option
281
326
 
282
- Overwrite Listen's default wait_for_delay, useful for kate-like editors through ssh access.
327
+ Overwrite Listen's default wait_for_delay, useful for kate-like editors through
328
+ ssh access or when guard is annoyingly running tasks multiple times.
283
329
 
284
330
  ```bash
285
331
  $ bundle exec guard start -y 1
@@ -498,8 +544,14 @@ guard :shell do
498
544
  end
499
545
  ```
500
546
 
501
- You can also define `watch`es outside of a `guard` plugin. This is useful to perform arbitrary Ruby
502
- logic (i.e. something project-specific).
547
+ *NOTE: Normally, most plugins expect the block to return a path or array of
548
+ paths - i.e. other plugins would think the `git status` output here is a
549
+ file path (which would cause an error), so this trick of returning the command
550
+ output only works for `guard-shell` plugin and other plugins that support
551
+ arbitrary results.*
552
+
553
+ You can also define `watch`es outside of a `guard` plugin. This is useful to
554
+ perform arbitrary Ruby logic (i.e. something project-specific).
503
555
 
504
556
  ```ruby
505
557
  watch(/.*/) { |m| puts "#{m[0]} changed." }
@@ -554,7 +606,7 @@ $ bundle exec guard -g specs
554
606
 
555
607
  Plugins that don't belong to a group are part of the `default` group.
556
608
 
557
- Another neat use of groups is to group dependant plugins and stop processing if one fails. In order
609
+ Another neat use of groups is to group dependent plugins and stop processing if one fails. In order
558
610
  to make this work, the group needs to have the `halt_on_fail` option enabled and the Guard plugin
559
611
  needs to throw `:task_has_failed` to indicate that the action was not successful.
560
612
 
@@ -616,7 +668,6 @@ Each notifier has a slightly different set of supported options:
616
668
  ```ruby
617
669
  notification :growl, sticky: true, host: '192.168.1.5', password: 'secret'
618
670
  notification :gntp, sticky: true, host: '192.168.1.5', password: 'secret'
619
- notification :growl_notify, sticky: true, priority: 0
620
671
  notification :libnotify, timeout: 5, transient: true, append: false, urgency: :critical
621
672
  notification :notifu, time: 5, nosound: true, xp: true
622
673
  notification :emacs
@@ -673,6 +724,8 @@ This comes in handy when you have large amounts of non-source data in you projec
673
724
  [`.rbx`, `.bundle`, `.DS_Store`, `.git`, `.hg` ,`.svn`, `bundle`, `log`, `tmp`, `vendor/bundle`](https://github.com/guard/listen/blob/master/lib/listen/silencer.rb#L5-L9)
674
725
  are ignored.
675
726
 
727
+ *NOTE: this option mostly helps when irrelevant changes are triggering guard tasks (e.g. a task starts before the editor finished saving all the files). Also, while it can reduce CPU time and increase responsiveness when using polling, instead, using `--watchdirs` is recommended for such "tuning" (e.g. large projects)*
728
+
676
729
  Please note that method only accept regexps. See [Listen README](https://github.com/guard/listen#ignore--ignore).
677
730
 
678
731
  To append to the default ignored files and directories, use the `ignore` method:
@@ -723,51 +776,13 @@ either an IO stream or a filename.
723
776
  Issues
724
777
  ------
725
778
 
726
- Please check guard's [GitHub issue tracker](https://github.com/guard/guard/issues) for known issues. Additionally you should check [listen's issue tracker](https://github.com/guard/listen/issues) for issues which affect guard's behaviour; for example, there is currently a nasty [bug preventing listen from watching files inside symlinked directories](https://github.com/guard/listen/issues/25).
727
-
728
- #### File an issue
729
-
730
- You can report bugs and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
731
-
732
- **Please don't ask question in the issue tracker**, instead ask them at one of our other places:
733
-
734
- * [Google+ community](https://plus.google.com/u/1/communities/110022199336250745477)
735
- * [Google group](http://groups.google.com/group/guard-dev)
736
- * [StackOverflow](http://stackoverflow.com/questions/tagged/guard)
737
- * IRC channel `#guard` (irc.freenode.net) for chatting
738
-
739
- Try to figure out where the issue belongs to: Is it an issue with Guard itself or with a Guard plugin you're
740
- using?
741
-
742
- When you file a bug, please try to follow these simple rules if applicable:
743
-
744
- * Make sure you've read the README carefully.
745
- * Make sure you run Guard with `bundle exec` first.
746
- * Add debug information to the issue by running Guard with the `--debug` option.
747
- * Add your `Guardfile` and `Gemfile` to the issue.
748
- * Provide information about your environment:
749
- * Your current versions of your OS, Ruby, Rubygems and Bundler.
750
- * Shared project folder with services like Dropbox, NFS, etc.
751
- * Make sure that the issue is reproducible with your description.
752
-
753
- **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
754
-
755
- Development
756
- -----------
757
-
758
- * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard/master/frames).
759
- * Source hosted at [GitHub](https://github.com/guard/guard).
779
+ Before reporting a problem, please read how to [File an issue](https://github.com/guard/guard/blob/master/CONTRIBUTING.md#file-an-issue).
760
780
 
761
- Pull requests are very welcome! Please try to follow these simple rules if applicable:
781
+ Development / Contributing
782
+ --------------------------
762
783
 
763
- * Please create a topic branch for every separate change you make.
764
- * Make sure your patches are well tested. All specs must pass on [Travis CI](https://travis-ci.org/guard/guard).
765
- * Update the [Yard](http://yardoc.org/) documentation.
766
- * Update the [README](https://github.com/guard/guard/blob/master/README.md).
767
- * Please **do not change** the version number.
784
+ See the [Contributing Guide](https://github.com/guard/guard/blob/master/CONTRIBUTING.md#development).
768
785
 
769
- For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
770
- `#guard` (irc.freenode.net).
771
786
 
772
787
  #### Open Commit Bit
773
788
 
data/bin/guard CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'guard'
4
- require 'guard/cli'
3
+ require "guard"
4
+ require "guard/cli"
5
5
 
6
6
  Guard::CLI.start
data/lib/guard.rb CHANGED
@@ -1,33 +1,41 @@
1
- require 'rbconfig'
2
-
3
- require 'guard/commander'
4
- require 'guard/deprecated_methods'
5
- require 'guard/deprecator'
6
- require 'guard/dsl'
7
- require 'guard/group'
8
- require 'guard/guardfile'
9
- require 'guard/interactor'
10
- require 'guard/notifier'
11
- require 'guard/plugin_util'
12
- require 'guard/runner'
13
- require 'guard/setuper'
14
- require 'guard/ui'
15
- require 'guard/watcher'
1
+ require "rbconfig"
2
+
3
+ require "guard/commander"
4
+ require "guard/deprecated_methods"
5
+ require "guard/deprecator"
6
+ require "guard/dsl"
7
+ require "guard/group"
8
+ require "guard/guardfile"
9
+ require "guard/interactor"
10
+ require "guard/notifier"
11
+ require "guard/plugin_util"
12
+ require "guard/runner"
13
+ require "guard/setuper"
14
+ require "guard/sheller"
15
+ require "guard/ui"
16
+ require "guard/watcher"
17
+ require "guard/reevaluator"
16
18
 
17
19
  # Guard is the main module for all Guard related modules and classes.
18
20
  # Also Guard plugins should use this namespace.
19
21
  #
20
22
  module Guard
21
-
22
- WINDOWS = RbConfig::CONFIG['host_os'] =~ %r!(msdos|mswin|djgpp|mingw)!
23
- DEV_NULL = WINDOWS ? 'NUL' : '/dev/null'
23
+ WINDOWS = RbConfig::CONFIG["host_os"] =~ /(?:msdos|mswin|djgpp|mingw)/
24
+ DEV_NULL = WINDOWS ? "NUL" : "/dev/null"
24
25
 
25
26
  extend Commander
26
27
  extend DeprecatedMethods
27
28
  extend Setuper
28
29
 
29
30
  class << self
30
- attr_accessor :runner, :listener, :lock, :scope, :running
31
+ attr_accessor :runner, :listener, :lock, :running
32
+
33
+ # Called by Pry scope command
34
+ attr_reader :scope
35
+
36
+ def scope=(new_scope)
37
+ @scope = new_scope
38
+ end
31
39
 
32
40
  # Smart accessor for retrieving specific plugins at once.
33
41
  #
@@ -45,8 +53,9 @@ module Guard
45
53
  # @example Filter plugins by Hash
46
54
  # Guard.plugins(name: 'rspec', group: 'backend')
47
55
  #
48
- # @param [String, Symbol, Regexp, Hash] filter the filter to apply to the plugins
49
- # @return [Array<Plugin>] the filtered plugin(s)
56
+ # @param [String, Symbol, Regexp, Hash] filter the filter to apply to the
57
+ # plugins
58
+ # @return [Plugin, Array<Plugin>] the filtered plugin(s)
50
59
  #
51
60
  def plugins(filter = nil)
52
61
  @plugins ||= []
@@ -54,26 +63,26 @@ module Guard
54
63
  return @plugins if filter.nil?
55
64
 
56
65
  filtered_plugins = case filter
57
- when String, Symbol
58
- @plugins.find_all do |plugin|
59
- plugin.name == filter.to_s.downcase.gsub('-', '')
60
- end
61
- when Regexp
62
- @plugins.find_all do |plugin|
63
- plugin.name =~ filter
64
- end
65
- when Hash
66
- @plugins.find_all do |plugin|
67
- filter.all? do |k, v|
68
- case k
69
- when :name
70
- plugin.name == v.to_s.downcase.gsub('-', '')
71
- when :group
72
- plugin.group.name == v.to_sym
73
- end
74
- end
75
- end
76
- end
66
+ when String, Symbol
67
+ @plugins.select do |plugin|
68
+ plugin.name == filter.to_s.downcase.gsub("-", "")
69
+ end
70
+ when Regexp
71
+ @plugins.select do |plugin|
72
+ plugin.name =~ filter
73
+ end
74
+ when Hash
75
+ @plugins.select do |plugin|
76
+ filter.all? do |k, v|
77
+ case k
78
+ when :name
79
+ plugin.name == v.to_s.downcase.gsub("-", "")
80
+ when :group
81
+ plugin.group.name == v.to_sym
82
+ end
83
+ end
84
+ end
85
+ end
77
86
 
78
87
  filtered_plugins
79
88
  end
@@ -94,8 +103,8 @@ module Guard
94
103
  # @example Find a plugin by Hash
95
104
  # Guard.plugin(name: 'rspec', group: 'backend')
96
105
  #
97
- # @param [String, Symbol, Regexp, Hash] filter the filter for finding the plugin
98
- # the Guard plugin
106
+ # @param [String, Symbol, Regexp, Hash] filter the filter for finding the
107
+ # plugin the Guard plugin
99
108
  # @return [Plugin, nil] the plugin found, nil otherwise
100
109
  #
101
110
  def plugin(filter)
@@ -123,14 +132,12 @@ module Guard
123
132
 
124
133
  return @groups if filter.nil?
125
134
 
126
- filtered_groups = case filter
127
- when String, Symbol
128
- @groups.find_all { |group| group.name == filter.to_sym }
129
- when Regexp
130
- @groups.find_all { |group| group.name.to_s =~ filter }
131
- end
132
-
133
- filtered_groups
135
+ case filter
136
+ when String, Symbol
137
+ @groups.select { |group| group.name == filter.to_sym }
138
+ when Regexp
139
+ @groups.select { |group| group.name.to_s =~ filter }
140
+ end
134
141
  end
135
142
 
136
143
  # Smart accessor for retrieving a specific group.
@@ -156,18 +163,17 @@ module Guard
156
163
  # Add a Guard plugin to use.
157
164
  #
158
165
  # @param [String] name the Guard name
159
- # @param [Hash] options the plugin options (see the given Guard documentation)
160
- # @option options [String] group the group to which the Guard plugin belongs
166
+ # @param [Hash] options the plugin options (see Plugin documentation)
167
+ # @option options [String] group the group to which the plugin belongs
161
168
  # @option options [Array<Watcher>] watchers the list of declared watchers
162
169
  # @option options [Array<Hash>] callbacks the list of callbacks
163
170
  # @return [Plugin] the added Guard plugin
164
171
  # @see Plugin
165
172
  #
166
173
  def add_plugin(name, options = {})
167
- plugin_instance = ::Guard::PluginUtil.new(name).initialize_plugin(options)
168
- @plugins << plugin_instance
169
-
170
- plugin_instance
174
+ instance = ::Guard::PluginUtil.new(name).initialize_plugin(options)
175
+ @plugins << instance
176
+ instance
171
177
  end
172
178
 
173
179
  # Add a Guard plugin group.
@@ -182,13 +188,12 @@ module Guard
182
188
  # @see Group
183
189
  #
184
190
  def add_group(name, options = {})
185
- unless group = group(name)
191
+ unless (group = group(name))
186
192
  group = ::Guard::Group.new(name, options)
187
193
  @groups << group
188
194
  end
189
195
 
190
196
  group
191
197
  end
192
-
193
198
  end
194
199
  end
data/lib/guard/cli.rb CHANGED
@@ -1,122 +1,121 @@
1
- require 'thor'
1
+ require "thor"
2
2
 
3
- require 'guard'
4
- require 'guard/version'
5
- require 'guard/dsl_describer'
6
- require 'guard/guardfile'
3
+ require "guard"
4
+ require "guard/version"
5
+ require "guard/dsl_describer"
6
+ require "guard/guardfile"
7
7
 
8
8
  module Guard
9
-
10
- # Facade for the Guard command line interface managed by [Thor](https://github.com/wycats/thor).
11
- # This is the main interface to Guard that is called by the Guard binary `bin/guard`.
12
- # Do not put any logic in here, create a class and delegate instead.
9
+ # Facade for the Guard command line interface managed by
10
+ # [Thor](https://github.com/wycats/thor).
11
+ #
12
+ # This is the main interface to Guard that is called by the Guard binary
13
+ # `bin/guard`. Do not put any logic in here, create a class and delegate
14
+ # instead.
13
15
  #
14
16
  class CLI < Thor
15
-
16
17
  default_task :start
17
18
 
18
- desc 'start', 'Starts Guard'
19
+ desc "start", "Starts Guard"
19
20
 
20
21
  method_option :clear,
21
22
  type: :boolean,
22
23
  default: false,
23
- aliases: '-c',
24
- banner: 'Auto clear shell before each action'
24
+ aliases: "-c",
25
+ banner: "Auto clear shell before each action"
25
26
 
26
27
  method_option :notify,
27
28
  type: :boolean,
28
29
  default: true,
29
- aliases: '-n',
30
- banner: 'Notifications feature'
30
+ aliases: "-n",
31
+ banner: "Notifications feature"
31
32
 
32
33
  method_option :debug,
33
34
  type: :boolean,
34
35
  default: false,
35
- aliases: '-d',
36
- banner: 'Show debug information'
36
+ aliases: "-d",
37
+ banner: "Show debug information"
37
38
 
38
39
  method_option :group,
39
40
  type: :array,
40
41
  default: [],
41
- aliases: '-g',
42
- banner: 'Run only the passed groups'
42
+ aliases: "-g",
43
+ banner: "Run only the passed groups"
43
44
 
44
45
  method_option :plugin,
45
46
  type: :array,
46
47
  default: [],
47
- aliases: '-P',
48
- banner: 'Run only the passed plugins'
48
+ aliases: "-P",
49
+ banner: "Run only the passed plugins"
49
50
 
50
51
  method_option :watchdir,
51
52
  type: :array,
52
- aliases: '-w',
53
- banner: 'Specify the directories to watch'
53
+ aliases: "-w",
54
+ banner: "Specify the directories to watch"
54
55
 
55
56
  method_option :guardfile,
56
57
  type: :string,
57
- aliases: '-G',
58
- banner: 'Specify a Guardfile'
58
+ aliases: "-G",
59
+ banner: "Specify a Guardfile"
59
60
 
60
61
  method_option :no_interactions,
61
62
  type: :boolean,
62
63
  default: false,
63
- aliases: '-i',
64
- banner: 'Turn off completely any Guard terminal interactions'
64
+ aliases: "-i",
65
+ banner: "Turn off completely any Guard terminal interactions"
65
66
 
66
67
  method_option :no_bundler_warning,
67
68
  type: :boolean,
68
69
  default: false,
69
- aliases: '-B',
70
- banner: 'Turn off warning when Bundler is not present'
70
+ aliases: "-B",
71
+ banner: "Turn off warning when Bundler is not present"
71
72
 
72
73
  method_option :show_deprecations,
73
74
  type: :boolean,
74
75
  default: false,
75
- banner: 'Turn on deprecation warnings'
76
+ banner: "Turn on deprecation warnings"
76
77
 
77
78
  # Listen options
78
79
  method_option :latency,
79
80
  type: :numeric,
80
- aliases: '-l',
81
+ aliases: "-l",
81
82
  banner: 'Overwrite Listen\'s default latency'
82
83
 
83
84
  method_option :force_polling,
84
85
  type: :boolean,
85
86
  default: false,
86
- aliases: '-p',
87
- banner: 'Force usage of the Listen polling listener'
87
+ aliases: "-p",
88
+ banner: "Force usage of the Listen polling listener"
88
89
 
89
90
  method_option :wait_for_delay,
90
91
  type: :numeric,
91
- aliases: '-y',
92
+ aliases: "-y",
92
93
  banner: 'Overwrite Listen\'s default wait_for_delay'
93
94
 
94
95
  method_option :listen_on,
95
96
  type: :string,
96
- aliases: '-o',
97
+ aliases: "-o",
97
98
  default: false,
98
- banner: 'Specify a network address to Listen on for file change events (e.g. for use in VMs)'
99
+ banner: "Specify a network address to Listen on for "\
100
+ "file change events (e.g. for use in VMs)"
99
101
 
100
- # Start Guard by initializing the defined Guard plugins and watch the file system.
101
- # This is the default task, so calling `guard` is the same as calling `guard start`.
102
+ # Start Guard by initializing the defined Guard plugins and watch the file
103
+ # system.
104
+ #
105
+ # This is the default task, so calling `guard` is the same as calling
106
+ # `guard start`.
102
107
  #
103
108
  # @see Guard.start
104
109
  #
105
110
  def start
106
111
  _verify_bundler_presence unless options[:no_bundler_warning]
107
112
  ::Guard.start(options)
108
-
109
- return if ENV['GUARD_ENV'] == 'test'
110
-
111
- while ::Guard.running do
112
- sleep 0.5
113
- end
114
113
  end
115
114
 
116
- desc 'list', 'Lists Guard plugins that can be used with init'
115
+ desc "list", "Lists Guard plugins that can be used with init"
117
116
 
118
- # List the Guard plugins that are available for use in your system and marks
119
- # those that are currently used in your `Guardfile`.
117
+ # List the Guard plugins that are available for use in your system and
118
+ # marks those that are currently used in your `Guardfile`.
120
119
  #
121
120
  # @see Guard::DslDescriber.list
122
121
  #
@@ -124,7 +123,7 @@ module Guard
124
123
  ::Guard::DslDescriber.new(options).list
125
124
  end
126
125
 
127
- desc 'notifiers', 'Lists notifiers and its options'
126
+ desc "notifiers", "Lists notifiers and its options"
128
127
 
129
128
  # List the Notifiers for use in your system.
130
129
  #
@@ -134,7 +133,7 @@ module Guard
134
133
  ::Guard::DslDescriber.new(options).notifiers
135
134
  end
136
135
 
137
- desc 'version', 'Show the Guard version'
136
+ desc "version", "Show the Guard version"
138
137
  map %w(-v --version) => :version
139
138
 
140
139
  # Shows the current version of Guard.
@@ -142,16 +141,19 @@ module Guard
142
141
  # @see Guard::VERSION
143
142
  #
144
143
  def version
145
- puts "Guard version #{ ::Guard::VERSION }"
144
+ STDOUT.puts "Guard version #{ ::Guard::VERSION }"
146
145
  end
147
146
 
148
- desc 'init [GUARDS]', 'Generates a Guardfile at the current directory (if it is not already there) and adds all installed Guard plugins or the given GUARDS into it'
147
+ desc "init [GUARDS]", "Generates a Guardfile at the current directory"\
148
+ " (if it is not already there) and adds all installed Guard plugins"\
149
+ " or the given GUARDS into it"
149
150
 
150
151
  method_option :bare,
151
152
  type: :boolean,
152
153
  default: false,
153
- aliases: '-b',
154
- banner: 'Generate a bare Guardfile without adding any installed plugin into it'
154
+ aliases: "-b",
155
+ banner: "Generate a bare Guardfile without adding any"\
156
+ " installed plugin into it"
155
157
 
156
158
  # Initializes the templates of all installed Guard plugins and adds them
157
159
  # to the `Guardfile` when no Guard name is passed. When passing
@@ -160,10 +162,14 @@ module Guard
160
162
  # @see Guard::Guardfile.initialize_template
161
163
  # @see Guard::Guardfile.initialize_all_templates
162
164
  #
163
- # @param [Array<String>] plugin_names the name of the Guard plugins to initialize
165
+ # @param [Array<String>] plugin_names the name of the Guard plugins to
166
+ # initialize
164
167
  #
165
168
  def init(*plugin_names)
166
- _verify_bundler_presence
169
+ _verify_bundler_presence unless options[:no_bundler_warning]
170
+
171
+ ::Guard.reset_options(options) # Since UI.deprecated uses config
172
+ ::Guard.reset_evaluator(options) # for initialize_all_templates
167
173
 
168
174
  ::Guard::Guardfile.create_guardfile(abort_on_existence: options[:bare])
169
175
 
@@ -178,7 +184,7 @@ module Guard
178
184
  end
179
185
  end
180
186
 
181
- desc 'show', 'Show all defined Guard plugins and their options'
187
+ desc "show", "Show all defined Guard plugins and their options"
182
188
  map %w(-T) => :show
183
189
 
184
190
  # Shows all Guard plugins and their options that are defined in
@@ -196,8 +202,10 @@ module Guard
196
202
  # shows a hint to do so if not.
197
203
  #
198
204
  def _verify_bundler_presence
199
- if File.exists?('Gemfile') && !ENV['BUNDLE_GEMFILE']
200
- ::Guard::UI.info <<EOF
205
+ return unless File.exist?("Gemfile")
206
+ return if ENV["BUNDLE_GEMFILE"] || ENV["RUBYGEMS_GEMDEPS"]
207
+
208
+ ::Guard::UI.info <<EOF
201
209
 
202
210
  Guard here! It looks like your project has a Gemfile, yet you are running
203
211
  `guard` outside of Bundler. If this is your intent, feel free to ignore this
@@ -205,8 +213,6 @@ message. Otherwise, consider using `bundle exec guard` to ensure your
205
213
  dependencies are loaded correctly.
206
214
  (You can run `guard` with --no-bundler-warning to get rid of this message.)
207
215
  EOF
208
- end
209
216
  end
210
-
211
217
  end
212
218
  end