restart 1.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2bd483174fcf4bfc6cb4695b233dd2f0dfcfd7fd
4
+ data.tar.gz: ed85a1e9b51cc0fc36b8c2558f404daf82b249da
5
+ SHA512:
6
+ metadata.gz: fa2e9c17d4e5181deb3b7b64f93c68f3b3a7c0c8e88be54fa229208851d804774d84c89b03cf75d81b3a439b3f703494c5a2fb301022449d1a82260829ad5067
7
+ data.tar.gz: 1d80869537a574305cbb8bbbd2fbdafc1a5d0a81decd59c94f1f37ca1acded4deab87393eb47bbd02fa650c1476f4a878975968d693624904c33f806824de959
data/.gitignore ADDED
@@ -0,0 +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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in restart.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +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.
data/README.md ADDED
@@ -0,0 +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
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/restart ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'restart'
data/lib/restart.rb ADDED
@@ -0,0 +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
@@ -0,0 +1,3 @@
1
+ module Restart
2
+ VERSION = "1.0.1"
3
+ end
data/restart.gemspec ADDED
@@ -0,0 +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", "~> 2.7.9"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restart
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vais Salikhov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: listen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Runs your shell command, then re-runs it any time filesystem change is
56
+ detected. For example, "restart ruby test.rb" will run "ruby test.rb", then re-run
57
+ it after test.rb file changes (or any other files change in current working directory
58
+ or any subdirectories under it).
59
+ email:
60
+ - vsalikhov@gmail.com
61
+ executables:
62
+ - restart
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/restart
72
+ - lib/restart.rb
73
+ - lib/restart/version.rb
74
+ - restart.gemspec
75
+ homepage: http://github.com/vais/restart
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Runs your shell command, then re-runs it any time filesystem change is detected.
99
+ test_files: []