guard 1.8.3 → 2.0.0.pre
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/CHANGELOG.md +68 -10
- data/README.md +54 -33
- data/lib/guard.rb +133 -483
- data/lib/guard/cli.rb +78 -82
- data/lib/guard/commander.rb +121 -0
- data/lib/guard/commands/all.rb +1 -1
- data/lib/guard/commands/reload.rb +1 -1
- data/lib/guard/deprecated_methods.rb +59 -0
- data/lib/guard/deprecator.rb +107 -0
- data/lib/guard/dsl.rb +143 -329
- data/lib/guard/dsl_describer.rb +101 -57
- data/lib/guard/group.rb +27 -8
- data/lib/guard/guard.rb +25 -150
- data/lib/guard/guardfile.rb +35 -85
- data/lib/guard/guardfile/evaluator.rb +245 -0
- data/lib/guard/guardfile/generator.rb +89 -0
- data/lib/guard/interactor.rb +147 -163
- data/lib/guard/notifier.rb +83 -137
- data/lib/guard/notifiers/base.rb +220 -0
- data/lib/guard/notifiers/emacs.rb +39 -37
- data/lib/guard/notifiers/file_notifier.rb +29 -25
- data/lib/guard/notifiers/gntp.rb +68 -75
- data/lib/guard/notifiers/growl.rb +49 -52
- data/lib/guard/notifiers/growl_notify.rb +51 -56
- data/lib/guard/notifiers/libnotify.rb +41 -48
- data/lib/guard/notifiers/notifysend.rb +58 -38
- data/lib/guard/notifiers/rb_notifu.rb +54 -54
- data/lib/guard/notifiers/terminal_notifier.rb +48 -36
- data/lib/guard/notifiers/terminal_title.rb +23 -19
- data/lib/guard/notifiers/tmux.rb +110 -93
- data/lib/guard/options.rb +21 -0
- data/lib/guard/plugin.rb +66 -0
- data/lib/guard/plugin/base.rb +178 -0
- data/lib/guard/plugin/hooker.rb +123 -0
- data/lib/guard/plugin_util.rb +158 -0
- data/lib/guard/rake_task.rb +47 -0
- data/lib/guard/runner.rb +62 -82
- data/lib/guard/setuper.rb +248 -0
- data/lib/guard/ui.rb +24 -80
- data/lib/guard/ui/colors.rb +60 -0
- data/lib/guard/version.rb +1 -2
- data/lib/guard/watcher.rb +30 -30
- data/man/guard.1 +4 -4
- data/man/guard.1.html +6 -4
- metadata +25 -11
- data/lib/guard/hook.rb +0 -120
@@ -1,12 +1,14 @@
|
|
1
|
-
require 'guard/
|
1
|
+
require 'guard/notifiers/base'
|
2
2
|
|
3
3
|
module Guard
|
4
4
|
module Notifier
|
5
5
|
|
6
|
-
# System notifications using the
|
6
|
+
# System notifications using the
|
7
|
+
# [terminal-notifier-guard](https://github.com/Springest/terminal-notifier-guard)
|
8
|
+
# gem.
|
7
9
|
#
|
8
|
-
# This gem is available for OS X 10.8 Mountain Lion and sends notifications
|
9
|
-
# notification center.
|
10
|
+
# This gem is available for OS X 10.8 Mountain Lion and sends notifications
|
11
|
+
# to the OS X notification center.
|
10
12
|
#
|
11
13
|
# @example Add the `terminal-notifier-guard` gem to your `Gemfile`
|
12
14
|
# group :development
|
@@ -19,49 +21,59 @@ module Guard
|
|
19
21
|
# @example Add the `:terminal_notifier` notifier with configuration options to your `Guardfile`
|
20
22
|
# notification :terminal_notifier, app_name: "MyApp"
|
21
23
|
#
|
22
|
-
|
23
|
-
extend self
|
24
|
+
class TerminalNotifier < Base
|
24
25
|
|
25
|
-
|
26
|
+
def self.supported_hosts
|
27
|
+
%w[darwin]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.gem_name
|
31
|
+
'terminal-notifier-guard'
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.available?(opts = {})
|
35
|
+
super
|
36
|
+
_register!(opts) if require_gem_safely(opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Shows a system notification.
|
26
40
|
#
|
27
|
-
# @param [
|
28
|
-
# @param [Hash]
|
29
|
-
# @
|
41
|
+
# @param [String] message the notification message body
|
42
|
+
# @param [Hash] opts additional notification library options
|
43
|
+
# @option opts [String] type the notification type. Either 'success',
|
44
|
+
# 'pending', 'failed' or 'notify'
|
45
|
+
# @option opts [String] title the notification title
|
46
|
+
# @option opts [String] image the path to the notification image (ignored)
|
47
|
+
# @option opts [String] app_name name of your app
|
48
|
+
# @option opts [String] execute a command
|
49
|
+
# @option opts [String] activate an app bundle
|
50
|
+
# @option opts [String] open some url or file
|
30
51
|
#
|
31
|
-
def
|
32
|
-
|
52
|
+
def notify(message, opts = {})
|
53
|
+
self.class.require_gem_safely
|
54
|
+
title = opts[:title]
|
55
|
+
normalize_standard_options!(opts)
|
33
56
|
|
57
|
+
opts.delete(:image)
|
58
|
+
opts[:title] = title || [opts.delete(:app_name) { 'Guard' }, opts[:type].downcase.capitalize].join(' ')
|
59
|
+
|
60
|
+
::TerminalNotifier::Guard.execute(false, opts.merge(message: message))
|
61
|
+
end
|
62
|
+
|
63
|
+
# @private
|
64
|
+
#
|
65
|
+
def self._register!(options)
|
34
66
|
if ::TerminalNotifier::Guard.available?
|
35
67
|
true
|
36
68
|
else
|
37
|
-
|
69
|
+
unless options[:silent]
|
70
|
+
::Guard::UI.error 'The :terminal_notifier only runs on Mac OS X 10.8 and later.'
|
71
|
+
end
|
38
72
|
false
|
39
73
|
end
|
40
|
-
|
41
|
-
rescue LoadError, NameError
|
42
|
-
::Guard::UI.error "Please add \"gem 'terminal-notifier-guard'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
|
43
|
-
false
|
44
74
|
end
|
45
75
|
|
46
|
-
# Show a system notification.
|
47
|
-
#
|
48
|
-
# @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
|
49
|
-
# @param [String] title the notification title
|
50
|
-
# @param [String] message the notification message body
|
51
|
-
# @param [String] image the path to the notification image (ignored)
|
52
|
-
# @param [Hash] options additional notification library options
|
53
|
-
# @option options [String] app_name name of your app
|
54
|
-
# @option options [String] execute a command
|
55
|
-
# @option options [String] activate an app bundle
|
56
|
-
# @option options [String] open some url or file
|
57
|
-
#
|
58
|
-
def notify(type, title, message, image, options = { })
|
59
|
-
require 'terminal-notifier-guard'
|
60
|
-
options[:title] = title || [options[:app_name] || 'Guard', type.downcase.capitalize].join(' ')
|
61
|
-
options.merge!(:type => type.to_sym, :message => message)
|
62
|
-
options.delete :app_name if options[:app_name]
|
63
|
-
::TerminalNotifier::Guard.execute(false, options)
|
64
|
-
end
|
65
76
|
end
|
77
|
+
|
66
78
|
end
|
67
79
|
end
|
@@ -1,31 +1,35 @@
|
|
1
|
-
|
1
|
+
require 'guard/notifiers/base'
|
2
|
+
|
2
3
|
module Guard
|
3
4
|
module Notifier
|
4
|
-
module TerminalTitle
|
5
|
-
extend self
|
6
5
|
|
7
|
-
|
6
|
+
# Shows system notifications in the terminal title bar.
|
7
|
+
#
|
8
|
+
class TerminalTitle < Base
|
9
|
+
|
10
|
+
# Shows a system notification.
|
8
11
|
#
|
9
|
-
# @param [
|
10
|
-
# @
|
11
|
-
# @
|
12
|
+
# @param [Hash] opts additional notification library options
|
13
|
+
# @option opts [String] message the notification message body
|
14
|
+
# @option opts [String] type the notification type. Either 'success',
|
15
|
+
# 'pending', 'failed' or 'notify'
|
16
|
+
# @option opts [String] title the notification title
|
12
17
|
#
|
13
|
-
def
|
14
|
-
|
18
|
+
def notify(message, opts = {})
|
19
|
+
normalize_standard_options!(opts)
|
20
|
+
|
21
|
+
first_line = message.sub(/^\n/, '').sub(/\n.*/m, '')
|
22
|
+
|
23
|
+
puts "\e]2;[#{ opts[:title] }] #{ first_line }\a"
|
15
24
|
end
|
16
25
|
|
17
|
-
#
|
26
|
+
# Clears the terminal title
|
18
27
|
#
|
19
|
-
|
20
|
-
|
21
|
-
# @param [String] message the notification message body
|
22
|
-
# @param [String] image the path to the notification image
|
23
|
-
# @param [Hash] options additional notification library options
|
24
|
-
#
|
25
|
-
def notify(type, title, message, image, options = { })
|
26
|
-
first_line = message.sub(/^\n/, '').sub(/\n.*/m, '')
|
27
|
-
puts("\e]2;[#{ title }] #{ first_line }\a")
|
28
|
+
def self.turn_off
|
29
|
+
puts "\e]2;\a"
|
28
30
|
end
|
31
|
+
|
29
32
|
end
|
33
|
+
|
30
34
|
end
|
31
35
|
end
|
data/lib/guard/notifiers/tmux.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'guard/notifiers/base'
|
2
|
+
|
1
3
|
module Guard
|
2
4
|
module Notifier
|
3
5
|
|
@@ -8,100 +10,118 @@ module Guard
|
|
8
10
|
# notification :tmux
|
9
11
|
#
|
10
12
|
# @example Enable text messages
|
11
|
-
# notification :tmux, :
|
13
|
+
# notification :tmux, display_message: true
|
12
14
|
#
|
13
15
|
# @example Customize the tmux status colored for notifications
|
14
|
-
# notification :tmux, :
|
16
|
+
# notification :tmux, color_location: 'status-right-bg'
|
15
17
|
#
|
16
|
-
|
17
|
-
extend self
|
18
|
+
class Tmux < Base
|
18
19
|
|
19
|
-
# Default options for
|
20
|
+
# Default options for the tmux notifications.
|
20
21
|
DEFAULTS = {
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
22
|
+
client: 'tmux',
|
23
|
+
tmux_environment: 'TMUX',
|
24
|
+
success: 'green',
|
25
|
+
failed: 'red',
|
26
|
+
pending: 'yellow',
|
27
|
+
default: 'green',
|
28
|
+
timeout: 5,
|
29
|
+
display_message: false,
|
30
|
+
default_message_format: '%s - %s',
|
31
|
+
default_message_color: 'white',
|
32
|
+
line_separator: ' - ',
|
33
|
+
color_location: 'status-left-bg'
|
33
34
|
}
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if ENV[options.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
|
43
|
-
::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.' unless silent
|
36
|
+
def self.available?(opts = {})
|
37
|
+
super
|
38
|
+
|
39
|
+
if ENV[opts.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
|
40
|
+
unless opts[:silent]
|
41
|
+
::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.'
|
42
|
+
end
|
44
43
|
false
|
45
44
|
else
|
46
45
|
true
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# to `
|
49
|
+
# Shows a system notification.
|
50
|
+
#
|
51
|
+
# By default, the Tmux notifier only makes
|
52
|
+
# use of a color based notification, changing the background color of the
|
53
|
+
# `color_location` to the color defined in either the `success`,
|
54
|
+
# `failed`, `pending` or `default`, depending on the notification type.
|
55
|
+
# If you also want display a text message, you have to enable it explicit
|
56
|
+
# by setting `display_message` to `true`.
|
55
57
|
#
|
56
|
-
# @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
|
57
58
|
# @param [String] title the notification title
|
58
|
-
# @param [
|
59
|
-
# @
|
60
|
-
#
|
61
|
-
# @option
|
62
|
-
# @option
|
59
|
+
# @param [Hash] opts additional notification library options
|
60
|
+
# @option opts [String] type the notification type. Either 'success',
|
61
|
+
# 'pending', 'failed' or 'notify'
|
62
|
+
# @option opts [String] message the notification message body
|
63
|
+
# @option opts [String] image the path to the notification image
|
64
|
+
# @option opts [String] color_location the location where to draw the
|
65
|
+
# color notification
|
66
|
+
# @option opts [Boolean] display_message whether to display a message
|
67
|
+
# or not
|
63
68
|
#
|
64
|
-
def notify(
|
65
|
-
|
66
|
-
|
69
|
+
def notify(message, opts = {})
|
70
|
+
normalize_standard_options!(opts)
|
71
|
+
opts.delete(:image)
|
72
|
+
|
73
|
+
color_location = opts.fetch(:color_location, DEFAULTS[:color_location])
|
74
|
+
color = tmux_color(opts[:type], opts)
|
67
75
|
|
68
|
-
|
76
|
+
_run_client "set #{ color_location } #{ color }"
|
69
77
|
|
70
|
-
|
71
|
-
|
78
|
+
if opts.fetch(:display_message, DEFAULTS[:display_message])
|
79
|
+
display_message(opts.delete(:type).to_s, opts.delete(:title), message, opts)
|
80
|
+
end
|
72
81
|
end
|
73
82
|
|
74
|
-
#
|
83
|
+
# Displays a message in the status bar of tmux.
|
75
84
|
#
|
76
|
-
# @param [String] type the notification type. Either 'success',
|
85
|
+
# @param [String] type the notification type. Either 'success',
|
86
|
+
# 'pending', 'failed' or 'notify'
|
77
87
|
# @param [String] title the notification title
|
78
88
|
# @param [String] message the notification message body
|
79
89
|
# @param [Hash] options additional notification library options
|
80
|
-
# @option options [Integer] timeout the amount of seconds to show the
|
81
|
-
#
|
82
|
-
# @option options [String]
|
83
|
-
#
|
84
|
-
# @option options [String]
|
85
|
-
#
|
86
|
-
# @option options [String]
|
87
|
-
#
|
88
|
-
# @option options [String]
|
89
|
-
#
|
90
|
+
# @option options [Integer] timeout the amount of seconds to show the
|
91
|
+
# message in the status bar
|
92
|
+
# @option options [String] success_message_format a string to use as
|
93
|
+
# formatter for the success message.
|
94
|
+
# @option options [String] failed_message_format a string to use as
|
95
|
+
# formatter for the failed message.
|
96
|
+
# @option options [String] pending_message_format a string to use as
|
97
|
+
# formatter for the pending message.
|
98
|
+
# @option options [String] default_message_format a string to use as
|
99
|
+
# formatter when no format per type is defined.
|
100
|
+
# @option options [String] success_message_color the success notification
|
101
|
+
# foreground color name.
|
102
|
+
# @option options [String] failed_message_color the failed notification
|
103
|
+
# foreground color name.
|
104
|
+
# @option options [String] pending_message_color the pending notification
|
105
|
+
# foreground color name.
|
106
|
+
# @option options [String] default_message_color a notification
|
107
|
+
# foreground color to use when no color per type is defined.
|
108
|
+
# @option options [String] line_separator a string to use instead of a
|
109
|
+
# line-break.
|
90
110
|
#
|
91
|
-
def display_message(type, title, message,
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
111
|
+
def display_message(type, title, message, opts = {})
|
112
|
+
message_format = opts.fetch("#{ type }_message_format".to_sym, opts.fetch(:default_message_format, DEFAULTS[:default_message_format]))
|
113
|
+
message_color = opts.fetch("#{ type }_message_color".to_sym, opts.fetch(:default_message_color, DEFAULTS[:default_message_color]))
|
114
|
+
display_time = opts.fetch(:timeout, DEFAULTS[:timeout])
|
115
|
+
separator = opts.fetch(:line_separator, DEFAULTS[:line_separator])
|
116
|
+
|
117
|
+
color = tmux_color type, opts
|
118
|
+
formatted_message = message.split("\n").join(separator)
|
119
|
+
display_message = message_format % [title, formatted_message]
|
120
|
+
|
121
|
+
_run_client "set display-time #{ display_time * 1000 }"
|
122
|
+
_run_client "set message-fg #{ message_color }"
|
123
|
+
_run_client "set message-bg #{ color }"
|
124
|
+
_run_client "display-message '#{ display_message }'"
|
105
125
|
end
|
106
126
|
|
107
127
|
# Get the Tmux color for the notification type.
|
@@ -110,55 +130,51 @@ module Guard
|
|
110
130
|
# @param [String] type the notification type
|
111
131
|
# @return [String] the name of the emacs color
|
112
132
|
#
|
113
|
-
def tmux_color(type,
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
options[:failed] || DEFAULTS[:failed]
|
119
|
-
when 'pending'
|
120
|
-
options[:pending] || DEFAULTS[:pending]
|
121
|
-
else
|
122
|
-
options[:default] || DEFAULTS[:default]
|
123
|
-
end
|
133
|
+
def tmux_color(type, opts = {})
|
134
|
+
type = type.to_sym
|
135
|
+
type = :default unless [:success, :failed, :pending].include?(type)
|
136
|
+
|
137
|
+
opts.fetch(type, DEFAULTS[type])
|
124
138
|
end
|
125
139
|
|
126
140
|
# Notification starting, save the current Tmux settings
|
127
141
|
# and quiet the Tmux output.
|
128
142
|
#
|
129
|
-
def turn_on
|
143
|
+
def turn_on
|
130
144
|
unless @options_stored
|
131
|
-
|
132
|
-
|
145
|
+
_reset_options_store
|
133
146
|
`#{ DEFAULTS[:client] } show`.each_line do |line|
|
134
147
|
option, _, setting = line.chomp.partition(' ')
|
135
|
-
|
148
|
+
options_store[option] = setting
|
136
149
|
end
|
137
150
|
|
138
151
|
@options_stored = true
|
139
152
|
end
|
140
153
|
|
141
|
-
|
154
|
+
_run_client 'set quiet on'
|
142
155
|
end
|
143
156
|
|
144
157
|
# Notification stopping. Restore the previous Tmux state
|
145
158
|
# if available (existing options are restored, new options
|
146
159
|
# are unset) and unquiet the Tmux output.
|
147
160
|
#
|
148
|
-
def turn_off
|
161
|
+
def turn_off
|
149
162
|
if @options_stored
|
150
163
|
@options_store.each do |key, value|
|
151
164
|
if value
|
152
|
-
|
165
|
+
_run_client "set #{ key } #{ value }"
|
153
166
|
else
|
154
|
-
|
167
|
+
_run_client "set -u #{ key }"
|
155
168
|
end
|
156
169
|
end
|
157
|
-
|
158
|
-
reset_options_store
|
170
|
+
_reset_options_store
|
159
171
|
end
|
160
172
|
|
161
|
-
|
173
|
+
_run_client 'set quiet off'
|
174
|
+
end
|
175
|
+
|
176
|
+
def options_store
|
177
|
+
@options_store ||= {}
|
162
178
|
end
|
163
179
|
|
164
180
|
private
|
@@ -168,13 +184,13 @@ module Guard
|
|
168
184
|
super
|
169
185
|
end
|
170
186
|
|
171
|
-
def
|
187
|
+
def _run_client(args)
|
172
188
|
system("#{ DEFAULTS[:client] } #{args}")
|
173
189
|
end
|
174
190
|
|
175
191
|
# Reset the internal Tmux options store defaults.
|
176
192
|
#
|
177
|
-
def
|
193
|
+
def _reset_options_store
|
178
194
|
@options_stored = false
|
179
195
|
@options_store = {
|
180
196
|
'status-left-bg' => nil,
|
@@ -188,5 +204,6 @@ module Guard
|
|
188
204
|
end
|
189
205
|
|
190
206
|
end
|
207
|
+
|
191
208
|
end
|
192
209
|
end
|