guard 1.4.0 → 2.18.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.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -677
  3. data/LICENSE +4 -2
  4. data/README.md +91 -753
  5. data/bin/_guard-core +11 -0
  6. data/bin/guard +108 -3
  7. data/lib/guard/aruba_adapter.rb +59 -0
  8. data/lib/guard/cli/environments/bundler.rb +22 -0
  9. data/lib/guard/cli/environments/evaluate_only.rb +35 -0
  10. data/lib/guard/cli/environments/valid.rb +69 -0
  11. data/lib/guard/cli.rb +129 -128
  12. data/lib/guard/commander.rb +104 -0
  13. data/lib/guard/commands/all.rb +37 -0
  14. data/lib/guard/commands/change.rb +31 -0
  15. data/lib/guard/commands/notification.rb +26 -0
  16. data/lib/guard/commands/pause.rb +29 -0
  17. data/lib/guard/commands/reload.rb +36 -0
  18. data/lib/guard/commands/scope.rb +38 -0
  19. data/lib/guard/commands/show.rb +24 -0
  20. data/lib/guard/config.rb +18 -0
  21. data/lib/guard/deprecated/dsl.rb +45 -0
  22. data/lib/guard/deprecated/evaluator.rb +39 -0
  23. data/lib/guard/deprecated/guard.rb +328 -0
  24. data/lib/guard/deprecated/guardfile.rb +84 -0
  25. data/lib/guard/deprecated/watcher.rb +27 -0
  26. data/lib/guard/dsl.rb +332 -363
  27. data/lib/guard/dsl_describer.rb +132 -122
  28. data/lib/guard/dsl_reader.rb +51 -0
  29. data/lib/guard/group.rb +34 -14
  30. data/lib/guard/guardfile/evaluator.rb +232 -0
  31. data/lib/guard/guardfile/generator.rb +128 -0
  32. data/lib/guard/guardfile.rb +24 -60
  33. data/lib/guard/interactor.rb +31 -255
  34. data/lib/guard/internals/debugging.rb +68 -0
  35. data/lib/guard/internals/groups.rb +40 -0
  36. data/lib/guard/internals/helpers.rb +13 -0
  37. data/lib/guard/internals/plugins.rb +53 -0
  38. data/lib/guard/internals/queue.rb +51 -0
  39. data/lib/guard/internals/scope.rb +121 -0
  40. data/lib/guard/internals/session.rb +180 -0
  41. data/lib/guard/internals/state.rb +25 -0
  42. data/lib/guard/internals/tracing.rb +33 -0
  43. data/lib/guard/internals/traps.rb +10 -0
  44. data/lib/guard/jobs/base.rb +21 -0
  45. data/lib/guard/jobs/pry_wrapper.rb +336 -0
  46. data/lib/guard/jobs/sleep.rb +26 -0
  47. data/lib/guard/notifier.rb +46 -212
  48. data/lib/guard/options.rb +22 -0
  49. data/lib/guard/plugin.rb +303 -0
  50. data/lib/guard/plugin_util.rb +191 -0
  51. data/lib/guard/rake_task.rb +42 -0
  52. data/lib/guard/runner.rb +80 -140
  53. data/lib/guard/templates/Guardfile +14 -0
  54. data/lib/guard/terminal.rb +13 -0
  55. data/lib/guard/ui/colors.rb +56 -0
  56. data/lib/guard/ui/config.rb +70 -0
  57. data/lib/guard/ui/logger.rb +30 -0
  58. data/lib/guard/ui.rb +163 -128
  59. data/lib/guard/version.rb +1 -2
  60. data/lib/guard/watcher/pattern/deprecated_regexp.rb +45 -0
  61. data/lib/guard/watcher/pattern/match_result.rb +18 -0
  62. data/lib/guard/watcher/pattern/matcher.rb +33 -0
  63. data/lib/guard/watcher/pattern/pathname_path.rb +15 -0
  64. data/lib/guard/watcher/pattern/simple_path.rb +23 -0
  65. data/lib/guard/watcher/pattern.rb +24 -0
  66. data/lib/guard/watcher.rb +52 -95
  67. data/lib/guard.rb +108 -376
  68. data/lib/tasks/releaser.rb +116 -0
  69. data/man/guard.1 +12 -9
  70. data/man/guard.1.html +18 -12
  71. metadata +148 -77
  72. data/images/guard.png +0 -0
  73. data/lib/guard/guard.rb +0 -156
  74. data/lib/guard/hook.rb +0 -120
  75. data/lib/guard/interactors/coolline.rb +0 -64
  76. data/lib/guard/interactors/helpers/completion.rb +0 -32
  77. data/lib/guard/interactors/helpers/terminal.rb +0 -46
  78. data/lib/guard/interactors/readline.rb +0 -94
  79. data/lib/guard/interactors/simple.rb +0 -19
  80. data/lib/guard/notifiers/emacs.rb +0 -69
  81. data/lib/guard/notifiers/gntp.rb +0 -118
  82. data/lib/guard/notifiers/growl.rb +0 -99
  83. data/lib/guard/notifiers/growl_notify.rb +0 -92
  84. data/lib/guard/notifiers/libnotify.rb +0 -96
  85. data/lib/guard/notifiers/notifysend.rb +0 -84
  86. data/lib/guard/notifiers/rb_notifu.rb +0 -102
  87. data/lib/guard/notifiers/terminal_notifier.rb +0 -66
  88. data/lib/guard/notifiers/tmux.rb +0 -69
  89. data/lib/guard/version.rbc +0 -130
@@ -0,0 +1,104 @@
1
+ require "listen"
2
+
3
+ require "guard/notifier"
4
+ require "guard/interactor"
5
+ require "guard/runner"
6
+ require "guard/dsl_describer"
7
+
8
+ require "guard/internals/state"
9
+
10
+ module Guard
11
+ # Commands supported by guard
12
+ module Commander
13
+ # Start Guard by evaluating the `Guardfile`, initializing declared Guard
14
+ # plugins and starting the available file change listener.
15
+ # Main method for Guard that is called from the CLI when Guard starts.
16
+ #
17
+ # - Setup Guard internals
18
+ # - Evaluate the `Guardfile`
19
+ # - Configure Notifiers
20
+ # - Initialize the declared Guard plugins
21
+ # - Start the available file change listener
22
+ #
23
+ # @option options [Boolean] clear if auto clear the UI should be done
24
+ # @option options [Boolean] notify if system notifications should be shown
25
+ # @option options [Boolean] debug if debug output should be shown
26
+ # @option options [Array<String>] group the list of groups to start
27
+ # @option options [String] watchdir the director to watch
28
+ # @option options [String] guardfile the path to the Guardfile
29
+ # @see CLI#start
30
+ #
31
+ def start(options = {})
32
+ setup(options)
33
+ UI.debug "Guard starts all plugins"
34
+ Runner.new.run(:start)
35
+ listener.start
36
+
37
+ watched = Guard.state.session.watchdirs.join("', '")
38
+ UI.info "Guard is now watching at '#{ watched }'"
39
+
40
+ exitcode = 0
41
+ begin
42
+ while interactor.foreground != :exit
43
+ Guard.queue.process while Guard.queue.pending?
44
+ end
45
+ rescue Interrupt
46
+ rescue SystemExit => e
47
+ exitcode = e.status
48
+ end
49
+
50
+ exitcode
51
+ ensure
52
+ stop
53
+ end
54
+
55
+ def stop
56
+ listener&.stop
57
+ interactor&.background
58
+ UI.debug "Guard stops all plugins"
59
+ Runner.new.run(:stop)
60
+ Notifier.disconnect
61
+ UI.info "Bye bye...", reset: true
62
+ end
63
+
64
+ # Reload Guardfile and all Guard plugins currently enabled.
65
+ # If no scope is given, then the Guardfile will be re-evaluated,
66
+ # which results in a stop/start, which makes the reload obsolete.
67
+ #
68
+ # @param [Hash] scopes hash with a Guard plugin or a group scope
69
+ #
70
+ def reload(scopes = {})
71
+ UI.clear(force: true)
72
+ UI.action_with_scopes("Reload", scopes)
73
+ Runner.new.run(:reload, scopes)
74
+ end
75
+
76
+ # Trigger `run_all` on all Guard plugins currently enabled.
77
+ #
78
+ # @param [Hash] scopes hash with a Guard plugin or a group scope
79
+ #
80
+ def run_all(scopes = {})
81
+ UI.clear(force: true)
82
+ UI.action_with_scopes("Run", scopes)
83
+ Runner.new.run(:run_all, scopes)
84
+ end
85
+
86
+ # Pause Guard listening to file changes.
87
+ #
88
+ def pause(expected = nil)
89
+ paused = listener.paused?
90
+ states = { paused: true, unpaused: false, toggle: !paused }
91
+ pause = states[expected || :toggle]
92
+ fail ArgumentError, "invalid mode: #{expected.inspect}" if pause.nil?
93
+ return if pause == paused
94
+
95
+ listener.public_send(pause ? :pause : :start)
96
+ UI.info "File event handling has been #{pause ? 'paused' : 'resumed'}"
97
+ end
98
+
99
+ def show
100
+ DslDescriber.new.show
101
+ end
102
+ end
103
+ extend Commander
104
+ end
@@ -0,0 +1,37 @@
1
+ # required for async_queue_add
2
+ require "pry"
3
+
4
+ require "guard"
5
+
6
+ module Guard
7
+ module Commands
8
+ class All
9
+ def self.import
10
+ Pry::Commands.create_command "all" do
11
+ group "Guard"
12
+ description "Run all plugins."
13
+
14
+ banner <<-BANNER
15
+ Usage: all <scope>
16
+
17
+ Run the Guard plugin `run_all` action.
18
+
19
+ You may want to specify an optional scope to the action,
20
+ either the name of a Guard plugin or a plugin group.
21
+ BANNER
22
+
23
+ def process(*entries)
24
+ scopes, unknown = Guard.state.session.convert_scope(entries)
25
+
26
+ unless unknown.empty?
27
+ output.puts "Unknown scopes: #{ unknown.join(', ') }"
28
+ return
29
+ end
30
+
31
+ Guard.async_queue_add([:guard_run_all, scopes])
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require "pry"
2
+
3
+ require "guard"
4
+
5
+ module Guard
6
+ module Commands
7
+ class Change
8
+ def self.import
9
+ Pry::Commands.create_command "change" do
10
+ group "Guard"
11
+ description "Trigger a file change."
12
+
13
+ banner <<-BANNER
14
+ Usage: change <file> <other_file>
15
+
16
+ Pass the given files to the Guard plugin `run_on_changes` action.
17
+ BANNER
18
+
19
+ def process(*files)
20
+ if files.empty?
21
+ output.puts "Please specify a file."
22
+ return
23
+ end
24
+
25
+ Guard.async_queue_add(modified: files, added: [], removed: [])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ require "pry"
2
+
3
+ require "guard/notifier"
4
+
5
+ module Guard
6
+ module Commands
7
+ class Notification
8
+ def self.import
9
+ Pry::Commands.create_command "notification" do
10
+ group "Guard"
11
+ description "Toggles the notifications."
12
+
13
+ banner <<-BANNER
14
+ Usage: notification
15
+
16
+ Toggles the notifications on and off.
17
+ BANNER
18
+
19
+ def process
20
+ Notifier.toggle
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ require "pry"
2
+
3
+ require "guard"
4
+
5
+ module Guard
6
+ module Commands
7
+ class Pause
8
+ def self.import
9
+ Pry::Commands.create_command "pause" do
10
+ group "Guard"
11
+ description "Toggles the file listener."
12
+
13
+ banner <<-BANNER
14
+ Usage: pause
15
+
16
+ Toggles the file listener on and off.
17
+
18
+ When the file listener is paused, the default Guard Pry
19
+ prompt will show the pause sign `[p]`.
20
+ BANNER
21
+
22
+ def process
23
+ ::Guard.async_queue_add([:guard_pause])
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ require "pry"
2
+
3
+ require "guard"
4
+
5
+ module Guard
6
+ module Commands
7
+ class Reload
8
+ def self.import
9
+ Pry::Commands.create_command "reload" do
10
+ group "Guard"
11
+ description "Reload all plugins."
12
+
13
+ banner <<-BANNER
14
+ Usage: reload <scope>
15
+
16
+ Run the Guard plugin `reload` action.
17
+
18
+ You may want to specify an optional scope to the action,
19
+ either the name of a Guard plugin or a plugin group.
20
+ BANNER
21
+
22
+ def process(*entries)
23
+ scopes, unknown = Guard.state.session.convert_scope(entries)
24
+
25
+ unless unknown.empty?
26
+ output.puts "Unknown scopes: #{ unknown.join(', ') }"
27
+ return
28
+ end
29
+
30
+ Guard.async_queue_add([:guard_reload, scopes])
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ require "pry"
2
+ require "guard/interactor"
3
+ require "guard"
4
+
5
+ module Guard
6
+ module Commands
7
+ class Scope
8
+ def self.import
9
+ Pry::Commands.create_command "scope" do
10
+ group "Guard"
11
+ description "Scope Guard actions to groups and plugins."
12
+
13
+ banner <<-BANNER
14
+ Usage: scope <scope>
15
+
16
+ Set the global Guard scope.
17
+ BANNER
18
+
19
+ def process(*entries)
20
+ scope, unknown = Guard.state.session.convert_scope(entries)
21
+
22
+ unless unknown.empty?
23
+ output.puts "Unknown scopes: #{unknown.join(',') }"
24
+ return
25
+ end
26
+
27
+ if scope[:plugins].empty? && scope[:groups].empty?
28
+ output.puts "Usage: scope <scope>"
29
+ return
30
+ end
31
+
32
+ Guard.state.scope.from_interactor(scope)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ require "pry"
2
+
3
+ module Guard
4
+ module Commands
5
+ class Show
6
+ def self.import
7
+ Pry::Commands.create_command "show" do
8
+ group "Guard"
9
+ description "Show all Guard plugins."
10
+
11
+ banner <<-BANNER
12
+ Usage: show
13
+
14
+ Show all defined Guard plugins and their options.
15
+ BANNER
16
+
17
+ def process
18
+ Guard.async_queue_add([:guard_show])
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require "nenv"
2
+
3
+ module Guard
4
+ config_class = Nenv::Builder.build do
5
+ create_method(:strict?)
6
+ create_method(:gem_silence_deprecations?)
7
+ end
8
+
9
+ class Config < config_class
10
+ def initialize
11
+ super "guard"
12
+ end
13
+
14
+ def silence_deprecations?
15
+ gem_silence_deprecations?
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ require "guard/config"
2
+ fail "Deprecations disabled (strict mode)" if Guard::Config.new.strict?
3
+
4
+ module Guard
5
+ module Deprecated
6
+ module Dsl
7
+ def self.add_deprecated(dsl_klass)
8
+ dsl_klass.send(:extend, ClassMethods)
9
+ end
10
+
11
+ MORE_INFO_ON_UPGRADING_TO_GUARD_2 = <<-EOS.gsub(/^\s*/, "")
12
+ For more information on how to upgrade for Guard 2.0, please head over
13
+ to: https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0%s
14
+ EOS
15
+
16
+ module ClassMethods
17
+ # @deprecated Use
18
+ # `Guard::Guardfile::Evaluator.new(options).evaluate_guardfile`
19
+ # instead.
20
+ #
21
+ # @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How
22
+ # to upgrade for Guard 2.0
23
+ #
24
+ EVALUATE_GUARDFILE = <<-EOS.gsub(/^\s*/, "")
25
+ Starting with Guard 2.0 'Guard::Dsl.evaluate_guardfile(options)' is
26
+ deprecated.
27
+
28
+ Please use
29
+ 'Guard::Guardfile::Evaluator.new(options).evaluate_guardfile'
30
+ instead.
31
+
32
+ #{MORE_INFO_ON_UPGRADING_TO_GUARD_2 % '#deprecated-methods-1'}
33
+ EOS
34
+
35
+ def evaluate_guardfile(options = {})
36
+ require "guard/guardfile/evaluator"
37
+ require "guard/ui"
38
+
39
+ UI.deprecation(EVALUATE_GUARDFILE)
40
+ ::Guard::Guardfile::Evaluator.new(options).evaluate_guardfile
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ require "guard/config"
2
+ fail "Deprecations disabled (strict mode)" if Guard::Config.new.strict?
3
+
4
+ require "guard/ui"
5
+
6
+ module Guard
7
+ module Deprecated
8
+ module Evaluator
9
+ def self.add_deprecated(klass)
10
+ klass.send(:include, self)
11
+ end
12
+
13
+ EVALUATE_GUARDFILE = <<-EOS.gsub(/^\s*/, "")
14
+ Starting with Guard 2.8.3 'Guard::Evaluator#evaluate_guardfile' is
15
+ deprecated in favor of '#evaluate'.
16
+ EOS
17
+
18
+ REEVALUATE_GUARDFILE = <<-EOS.gsub(/^\s*/, "")
19
+ Starting with Guard 2.8.3 'Guard::Evaluator#reevaluate_guardfile' is
20
+ deprecated in favor of '#reevaluate'.
21
+
22
+ NOTE: this method no longer does anything since it could not be
23
+ implemented reliably.
24
+ EOS
25
+
26
+ def evaluate_guardfile
27
+ UI.deprecation(EVALUATE_GUARDFILE)
28
+ evaluate
29
+ end
30
+
31
+ def reevaluate_guardfile
32
+ # require guard only when needed, because
33
+ # guard's deprecations require us
34
+ require "guard"
35
+ UI.deprecation(REEVALUATE_GUARDFILE)
36
+ end
37
+ end
38
+ end
39
+ end