restart 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -14
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +58 -58
- data/Rakefile +2 -2
- data/lib/restart.rb +165 -165
- data/lib/restart/version.rb +3 -3
- data/restart.gemspec +25 -25
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca66f6c566aead10c36322c7ec101889aea52ac7
|
4
|
+
data.tar.gz: d822ab6899a4c6054973c4689a7a42e00e8f6aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 580360f9196c85abb452a2e48c88c85d0331dd13f72b45ff7ee999df81bae77d0eb07337329d2935494862d74920b071ae2c38463d8be03097cc3de6ec7bdf52
|
7
|
+
data.tar.gz: de1cbe504b5daae9d25e39d72cfba1a77dbaf65f38f42828789580ba893390a15114c54494aef88bb32782be16122dac2fef8234c9a223df8173f258c7a7d0f4
|
data/.gitignore
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
*.bundle
|
11
|
-
*.so
|
12
|
-
*.o
|
13
|
-
*.a
|
14
|
-
mkmf.log
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.bundle
|
11
|
+
*.so
|
12
|
+
*.o
|
13
|
+
*.a
|
14
|
+
mkmf.log
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in restart.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in restart.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2014 Vais Salikhov
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2014 Vais Salikhov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
# Restart
|
2
|
-
|
3
|
-
Runs your shell command, then re-runs it any time filesystem change is detected.
|
4
|
-
|
5
|
-
EXAMPLE: `restart ruby test.rb`
|
6
|
-
|
7
|
-
This will run `ruby test.rb`, then re-run it after the test.rb file changes (or any other files change in current working directory or any subdirectories under it).
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
`gem install restart`
|
12
|
-
|
13
|
-
## Windows Installation
|
14
|
-
|
15
|
-
The process of installing this gem involves building native extensions because of its dependency on the [listen](https://rubygems.org/gems/listen) gem. If you have not already installed [DevKit](http://rubyinstaller.org/add-ons/devkit/) from [RubyInstaller.org](http://rubyinstaller.org), you will need to get it installed and working on your system before installing any gems that depend on building native extensions. To get started, [download DevKit](http://rubyinstaller.org/downloads/), and follow [these step-by-step installation instructions](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit).
|
16
|
-
|
17
|
-
Once DevKit is installed and working, you are ready to install this gem:
|
18
|
-
|
19
|
-
`gem install restart`
|
20
|
-
|
21
|
-
It is _highly recommended_ that you also install the [wdm](https://rubygems.org/gems/wdm) gem, which enables [listen](https://rubygems.org/gems/listen) to receive filesystem event notifications from Windows instead of polling the filesystem for changes (you DO NOT want to use polling):
|
22
|
-
|
23
|
-
`gem install wdm`
|
24
|
-
|
25
|
-
That's all - you should now be able to start using the `restart` command.
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
```
|
30
|
-
restart [options] <your shell command>
|
31
|
-
|
32
|
-
OPTIONS:
|
33
|
-
-d, --dir DIR[,DIR...] Directory tree to watch for filesystem changes.
|
34
|
-
Examples:
|
35
|
-
restart -d app rackup
|
36
|
-
restart -d .,../test,../lib rake test
|
37
|
-
restart -d .,../test -d../lib rake test
|
38
|
-
restart -d . -d ../test -d ../lib rake test
|
39
|
-
|
40
|
-
-f, --file EXT[,EXT...] Only watch files with given extension, plus files
|
41
|
-
with matching name that do not have an extension.
|
42
|
-
Examples:
|
43
|
-
restart -f Rakefile rake
|
44
|
-
restart -f rb ruby test.rb
|
45
|
-
restart -f rb,yml ruby app.rb
|
46
|
-
restart -f rb -f yml ruby app.rb
|
47
|
-
|
48
|
-
-i, --ignore REGX[,REGX...] Ignore file paths matching regular expression.
|
49
|
-
Examples:
|
50
|
-
restart -i /foo/bar/
|
51
|
-
restart -i \.pid$,\.coffee$
|
52
|
-
restart -i \.pid$ -i \.coffee$
|
53
|
-
|
54
|
-
-c, --clear Clear screen between each run.
|
55
|
-
-e, --explain Show current values for all options and quit.
|
56
|
-
-v, --version Display version and quit.
|
57
|
-
-h, --help Display this help message and quit.
|
58
|
-
```
|
1
|
+
# Restart
|
2
|
+
|
3
|
+
Runs your shell command, then re-runs it any time filesystem change is detected.
|
4
|
+
|
5
|
+
EXAMPLE: `restart ruby test.rb`
|
6
|
+
|
7
|
+
This will run `ruby test.rb`, then re-run it after the test.rb file changes (or any other files change in current working directory or any subdirectories under it).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
`gem install restart`
|
12
|
+
|
13
|
+
## Windows Installation
|
14
|
+
|
15
|
+
The process of installing this gem involves building native extensions because of its dependency on the [listen](https://rubygems.org/gems/listen) gem. If you have not already installed [DevKit](http://rubyinstaller.org/add-ons/devkit/) from [RubyInstaller.org](http://rubyinstaller.org), you will need to get it installed and working on your system before installing any gems that depend on building native extensions. To get started, [download DevKit](http://rubyinstaller.org/downloads/), and follow [these step-by-step installation instructions](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit).
|
16
|
+
|
17
|
+
Once DevKit is installed and working, you are ready to install this gem:
|
18
|
+
|
19
|
+
`gem install restart`
|
20
|
+
|
21
|
+
It is _highly recommended_ that you also install the [wdm](https://rubygems.org/gems/wdm) gem, which enables [listen](https://rubygems.org/gems/listen) to receive filesystem event notifications from Windows instead of polling the filesystem for changes (you DO NOT want to use polling):
|
22
|
+
|
23
|
+
`gem install wdm`
|
24
|
+
|
25
|
+
That's all - you should now be able to start using the `restart` command.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```
|
30
|
+
restart [options] <your shell command>
|
31
|
+
|
32
|
+
OPTIONS:
|
33
|
+
-d, --dir DIR[,DIR...] Directory tree to watch for filesystem changes.
|
34
|
+
Examples:
|
35
|
+
restart -d app rackup
|
36
|
+
restart -d .,../test,../lib rake test
|
37
|
+
restart -d .,../test -d../lib rake test
|
38
|
+
restart -d . -d ../test -d ../lib rake test
|
39
|
+
|
40
|
+
-f, --file EXT[,EXT...] Only watch files with given extension, plus files
|
41
|
+
with matching name that do not have an extension.
|
42
|
+
Examples:
|
43
|
+
restart -f Rakefile rake
|
44
|
+
restart -f rb ruby test.rb
|
45
|
+
restart -f rb,yml ruby app.rb
|
46
|
+
restart -f rb -f yml ruby app.rb
|
47
|
+
|
48
|
+
-i, --ignore REGX[,REGX...] Ignore file paths matching regular expression.
|
49
|
+
Examples:
|
50
|
+
restart -i /foo/bar/
|
51
|
+
restart -i \.pid$,\.coffee$
|
52
|
+
restart -i \.pid$ -i \.coffee$
|
53
|
+
|
54
|
+
-c, --clear Clear screen between each run.
|
55
|
+
-e, --explain Show current values for all options and quit.
|
56
|
+
-v, --version Display version and quit.
|
57
|
+
-h, --help Display this help message and quit.
|
58
|
+
```
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
data/lib/restart.rb
CHANGED
@@ -1,165 +1,165 @@
|
|
1
|
-
require "restart/version"
|
2
|
-
|
3
|
-
Restart::BANNER = <<-BANNER
|
4
|
-
USAGE: restart [options] <your shell command>
|
5
|
-
|
6
|
-
Runs your shell command, then re-runs it any time filesystem change is detected.
|
7
|
-
|
8
|
-
EXAMPLE: restart ruby test.rb
|
9
|
-
|
10
|
-
This will run "ruby test.rb", then re-run it after test.rb file changes (or any
|
11
|
-
other files change in current working directory or any subdirectories under it).
|
12
|
-
|
13
|
-
See http://github.com/vais/restart for more info.
|
14
|
-
Version: #{ Restart::VERSION }
|
15
|
-
|
16
|
-
OPTIONS:
|
17
|
-
BANNER
|
18
|
-
|
19
|
-
require 'optparse'
|
20
|
-
options = {}
|
21
|
-
|
22
|
-
option_parser = OptionParser.new(Restart::BANNER, 28, ' ') do |opts|
|
23
|
-
|
24
|
-
options[:dir] = []
|
25
|
-
opts.on(
|
26
|
-
'-d', '--dir DIR[,DIR...]',
|
27
|
-
Array,
|
28
|
-
'Directory tree to watch for filesystem changes.',
|
29
|
-
'Examples:',
|
30
|
-
' restart -d app rackup',
|
31
|
-
' restart -d .,../test,../lib rake test',
|
32
|
-
' restart -d .,../test -d../lib rake test',
|
33
|
-
' restart -d . -d ../test -d ../lib rake test',
|
34
|
-
' '
|
35
|
-
) do |dirs|
|
36
|
-
dirs.each do |dir|
|
37
|
-
unless File.directory?(dir)
|
38
|
-
fail OptionParser::InvalidArgument, "#{ dir } is not a valid directory"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
options[:dir] += dirs
|
42
|
-
end
|
43
|
-
|
44
|
-
options[:file] = []
|
45
|
-
opts.on(
|
46
|
-
'-f', '--file EXT[,EXT...]',
|
47
|
-
Array,
|
48
|
-
'Only watch files with given extension, plus files',
|
49
|
-
'with matching name that do not have an extension.',
|
50
|
-
'Examples:',
|
51
|
-
' restart -f Rakefile rake',
|
52
|
-
' restart -f rb ruby test.rb',
|
53
|
-
' restart -f rb,yml ruby app.rb',
|
54
|
-
' restart -f rb -f yml ruby app.rb',
|
55
|
-
' '
|
56
|
-
) do |exts|
|
57
|
-
options[:file] += exts.map do |ext|
|
58
|
-
s = Regexp.quote(ext.sub(/^\./, ''))
|
59
|
-
/\.#{ s }$|^#{ s }$/i
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
options[:ignore] = []
|
64
|
-
opts.on(
|
65
|
-
'-i', '--ignore REGX[,REGX...]',
|
66
|
-
Array,
|
67
|
-
'Ignore file paths matching regular expression.',
|
68
|
-
'Examples:',
|
69
|
-
' restart -i /foo/bar/',
|
70
|
-
' restart -i \.pid$,\.coffee$',
|
71
|
-
' restart -i \.pid$ -i \.coffee$',
|
72
|
-
' '
|
73
|
-
) do |patterns|
|
74
|
-
options[:ignore] += patterns.map do |pattern|
|
75
|
-
Regexp.new(pattern)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
options[:clear] = false
|
80
|
-
opts.on('-c', '--clear', 'Clear screen between each run.') do
|
81
|
-
options[:clear] = true
|
82
|
-
end
|
83
|
-
|
84
|
-
options[:explain] = false
|
85
|
-
opts.on('-e', '--explain', 'Show current values for all options and quit.') do
|
86
|
-
options[:explain] = true
|
87
|
-
end
|
88
|
-
|
89
|
-
opts.on('-v', '--version', 'Display version and quit.') do
|
90
|
-
puts Restart::VERSION
|
91
|
-
exit
|
92
|
-
end
|
93
|
-
|
94
|
-
opts.on('-h', '--help', 'Display this help message and quit.') do
|
95
|
-
puts opts
|
96
|
-
exit
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
option_parser.order!
|
101
|
-
options[:dir] << '.' if options[:dir].empty?
|
102
|
-
options[:command] = ARGV.map{|s| s =~ /\s/ ? %Q{"#{ s }"} : s}.join(' ')
|
103
|
-
if options[:explain]
|
104
|
-
require 'pp'
|
105
|
-
options.delete(:explain)
|
106
|
-
pp options
|
107
|
-
exit
|
108
|
-
end
|
109
|
-
if options[:command].empty?
|
110
|
-
puts option_parser
|
111
|
-
exit
|
112
|
-
end
|
113
|
-
|
114
|
-
require 'listen'
|
115
|
-
restarting = false
|
116
|
-
process = Process.detach(spawn(options[:command]))
|
117
|
-
|
118
|
-
begin
|
119
|
-
require 'win32api'
|
120
|
-
ctrl_c = Win32API.new('Kernel32', 'GenerateConsoleCtrlEvent', 'II', 'I')
|
121
|
-
killer = proc do
|
122
|
-
ctrl_c.call(0, 0)
|
123
|
-
sleep 0.1
|
124
|
-
if process.alive?
|
125
|
-
Process.kill(:KILL, process.pid)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
clear = proc do
|
129
|
-
system 'cls'
|
130
|
-
end
|
131
|
-
rescue LoadError
|
132
|
-
killer = proc do
|
133
|
-
Process.kill(:INT, -Process.getpgrp)
|
134
|
-
sleep 0.1
|
135
|
-
if process.alive?
|
136
|
-
Process.kill(:KILL, process.pid)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
clear = proc do
|
140
|
-
system 'clear'
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
trap('INT') do
|
145
|
-
exit unless restarting || process.alive?
|
146
|
-
end
|
147
|
-
|
148
|
-
listener_options = {}
|
149
|
-
unless options[:file].empty?
|
150
|
-
listener_options[:only] = options[:file]
|
151
|
-
end
|
152
|
-
unless options[:ignore].empty?
|
153
|
-
listener_options[:ignore] = options[:ignore]
|
154
|
-
end
|
155
|
-
listener = Listen.to(*options[:dir], listener_options) do
|
156
|
-
restarting = true
|
157
|
-
killer.call
|
158
|
-
restarting = false
|
159
|
-
clear.call if options[:clear]
|
160
|
-
print "\n\e[7m#{ Time.now.strftime('%H:%M:%S') } #{ options[:command] }\e[0m\n\n"
|
161
|
-
process = Process.detach(spawn(options[:command]))
|
162
|
-
end
|
163
|
-
|
164
|
-
listener.start
|
165
|
-
sleep
|
1
|
+
require "restart/version"
|
2
|
+
|
3
|
+
Restart::BANNER = <<-BANNER
|
4
|
+
USAGE: restart [options] <your shell command>
|
5
|
+
|
6
|
+
Runs your shell command, then re-runs it any time filesystem change is detected.
|
7
|
+
|
8
|
+
EXAMPLE: restart ruby test.rb
|
9
|
+
|
10
|
+
This will run "ruby test.rb", then re-run it after test.rb file changes (or any
|
11
|
+
other files change in current working directory or any subdirectories under it).
|
12
|
+
|
13
|
+
See http://github.com/vais/restart for more info.
|
14
|
+
Version: #{ Restart::VERSION }
|
15
|
+
|
16
|
+
OPTIONS:
|
17
|
+
BANNER
|
18
|
+
|
19
|
+
require 'optparse'
|
20
|
+
options = {}
|
21
|
+
|
22
|
+
option_parser = OptionParser.new(Restart::BANNER, 28, ' ') do |opts|
|
23
|
+
|
24
|
+
options[:dir] = []
|
25
|
+
opts.on(
|
26
|
+
'-d', '--dir DIR[,DIR...]',
|
27
|
+
Array,
|
28
|
+
'Directory tree to watch for filesystem changes.',
|
29
|
+
'Examples:',
|
30
|
+
' restart -d app rackup',
|
31
|
+
' restart -d .,../test,../lib rake test',
|
32
|
+
' restart -d .,../test -d../lib rake test',
|
33
|
+
' restart -d . -d ../test -d ../lib rake test',
|
34
|
+
' '
|
35
|
+
) do |dirs|
|
36
|
+
dirs.each do |dir|
|
37
|
+
unless File.directory?(dir)
|
38
|
+
fail OptionParser::InvalidArgument, "#{ dir } is not a valid directory"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
options[:dir] += dirs
|
42
|
+
end
|
43
|
+
|
44
|
+
options[:file] = []
|
45
|
+
opts.on(
|
46
|
+
'-f', '--file EXT[,EXT...]',
|
47
|
+
Array,
|
48
|
+
'Only watch files with given extension, plus files',
|
49
|
+
'with matching name that do not have an extension.',
|
50
|
+
'Examples:',
|
51
|
+
' restart -f Rakefile rake',
|
52
|
+
' restart -f rb ruby test.rb',
|
53
|
+
' restart -f rb,yml ruby app.rb',
|
54
|
+
' restart -f rb -f yml ruby app.rb',
|
55
|
+
' '
|
56
|
+
) do |exts|
|
57
|
+
options[:file] += exts.map do |ext|
|
58
|
+
s = Regexp.quote(ext.sub(/^\./, ''))
|
59
|
+
/\.#{ s }$|^#{ s }$/i
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
options[:ignore] = []
|
64
|
+
opts.on(
|
65
|
+
'-i', '--ignore REGX[,REGX...]',
|
66
|
+
Array,
|
67
|
+
'Ignore file paths matching regular expression.',
|
68
|
+
'Examples:',
|
69
|
+
' restart -i /foo/bar/',
|
70
|
+
' restart -i \.pid$,\.coffee$',
|
71
|
+
' restart -i \.pid$ -i \.coffee$',
|
72
|
+
' '
|
73
|
+
) do |patterns|
|
74
|
+
options[:ignore] += patterns.map do |pattern|
|
75
|
+
Regexp.new(pattern)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
options[:clear] = false
|
80
|
+
opts.on('-c', '--clear', 'Clear screen between each run.') do
|
81
|
+
options[:clear] = true
|
82
|
+
end
|
83
|
+
|
84
|
+
options[:explain] = false
|
85
|
+
opts.on('-e', '--explain', 'Show current values for all options and quit.') do
|
86
|
+
options[:explain] = true
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on('-v', '--version', 'Display version and quit.') do
|
90
|
+
puts Restart::VERSION
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on('-h', '--help', 'Display this help message and quit.') do
|
95
|
+
puts opts
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
option_parser.order!
|
101
|
+
options[:dir] << '.' if options[:dir].empty?
|
102
|
+
options[:command] = ARGV.map{|s| s =~ /\s/ ? %Q{"#{ s }"} : s}.join(' ')
|
103
|
+
if options[:explain]
|
104
|
+
require 'pp'
|
105
|
+
options.delete(:explain)
|
106
|
+
pp options
|
107
|
+
exit
|
108
|
+
end
|
109
|
+
if options[:command].empty?
|
110
|
+
puts option_parser
|
111
|
+
exit
|
112
|
+
end
|
113
|
+
|
114
|
+
require 'listen'
|
115
|
+
restarting = false
|
116
|
+
process = Process.detach(spawn(options[:command]))
|
117
|
+
|
118
|
+
begin
|
119
|
+
require 'win32api'
|
120
|
+
ctrl_c = Win32API.new('Kernel32', 'GenerateConsoleCtrlEvent', 'II', 'I')
|
121
|
+
killer = proc do
|
122
|
+
ctrl_c.call(0, 0)
|
123
|
+
sleep 0.1
|
124
|
+
if process.alive?
|
125
|
+
Process.kill(:KILL, process.pid)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
clear = proc do
|
129
|
+
system 'cls'
|
130
|
+
end
|
131
|
+
rescue LoadError
|
132
|
+
killer = proc do
|
133
|
+
Process.kill(:INT, -Process.getpgrp)
|
134
|
+
sleep 0.1
|
135
|
+
if process.alive?
|
136
|
+
Process.kill(:KILL, process.pid)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
clear = proc do
|
140
|
+
system 'clear'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
trap('INT') do
|
145
|
+
exit unless restarting || process.alive?
|
146
|
+
end
|
147
|
+
|
148
|
+
listener_options = {}
|
149
|
+
unless options[:file].empty?
|
150
|
+
listener_options[:only] = options[:file]
|
151
|
+
end
|
152
|
+
unless options[:ignore].empty?
|
153
|
+
listener_options[:ignore] = options[:ignore]
|
154
|
+
end
|
155
|
+
listener = Listen.to(*options[:dir], listener_options) do
|
156
|
+
restarting = true
|
157
|
+
killer.call
|
158
|
+
restarting = false
|
159
|
+
clear.call if options[:clear]
|
160
|
+
print "\n\e[7m#{ Time.now.strftime('%H:%M:%S') } #{ options[:command] }\e[0m\n\n"
|
161
|
+
process = Process.detach(spawn(options[:command]))
|
162
|
+
end
|
163
|
+
|
164
|
+
listener.start
|
165
|
+
sleep
|
data/lib/restart/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Restart
|
2
|
-
VERSION = "1.0.
|
3
|
-
end
|
1
|
+
module Restart
|
2
|
+
VERSION = "1.0.2"
|
3
|
+
end
|
data/restart.gemspec
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'restart/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "restart"
|
8
|
-
spec.version = Restart::VERSION
|
9
|
-
spec.authors = ["Vais Salikhov"]
|
10
|
-
spec.email = ["vsalikhov@gmail.com"]
|
11
|
-
spec.summary = %q{Runs your shell command, then re-runs it any time filesystem change is detected.}
|
12
|
-
spec.description = %q{Runs your shell command, then re-runs it any time filesystem change is detected. For example, "restart ruby test.rb" will run "ruby test.rb", then re-run it after test.rb file changes (or any other files change in current working directory or any subdirectories under it).}
|
13
|
-
spec.homepage = "http://github.com/vais/restart"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_runtime_dependency "listen", "~>
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'restart/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "restart"
|
8
|
+
spec.version = Restart::VERSION
|
9
|
+
spec.authors = ["Vais Salikhov"]
|
10
|
+
spec.email = ["vsalikhov@gmail.com"]
|
11
|
+
spec.summary = %q{Runs your shell command, then re-runs it any time filesystem change is detected.}
|
12
|
+
spec.description = %q{Runs your shell command, then re-runs it any time filesystem change is detected. For example, "restart ruby test.rb" will run "ruby test.rb", then re-run it after test.rb file changes (or any other files change in current working directory or any subdirectories under it).}
|
13
|
+
spec.homepage = "http://github.com/vais/restart"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "listen", "~> 3.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vais Salikhov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,3 +97,4 @@ signing_key:
|
|
97
97
|
specification_version: 4
|
98
98
|
summary: Runs your shell command, then re-runs it any time filesystem change is detected.
|
99
99
|
test_files: []
|
100
|
+
has_rdoc:
|