guard-go 0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +23 -0
- data/Rakefile +2 -0
- data/guard-go.gemspec +19 -0
- data/lib/guard/go/runner.rb +52 -0
- data/lib/guard/go/templates/Guardfile +6 -0
- data/lib/guard/go/version.rb +5 -0
- data/lib/guard/go.rb +43 -0
- data/lib/guard-go.rb +1 -0
- metadata +67 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Victor Castell
|
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,23 @@
|
|
1
|
+
# Guard::Go
|
2
|
+
|
3
|
+
Guard Go runs go programs and restart when file changes
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'guard-go'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install guard-go
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ guard init go
|
22
|
+
|
23
|
+
This will create your Guardfile. Edit it and configure your application file name.
|
data/Rakefile
ADDED
data/guard-go.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/guard/go/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Victor Castell"]
|
6
|
+
gem.email = ["victorcoder@gmail.com"]
|
7
|
+
gem.description = %q{Guard gem for Go}
|
8
|
+
gem.summary = %q{Guard gem for launching go files}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "guard-go"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Guard::GoVersion::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'guard', '>= 1.0.0'
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
class GoRunner
|
5
|
+
MAX_WAIT_COUNT = 10
|
6
|
+
|
7
|
+
attr_reader :options, :pid
|
8
|
+
|
9
|
+
def initialize(file, options)
|
10
|
+
@file = file
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
run_go_command!
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop
|
19
|
+
ps_go_pid.each do |pid|
|
20
|
+
system %{kill -KILL #{pid}}
|
21
|
+
end
|
22
|
+
while ps_go_pid.count > 0
|
23
|
+
wait sleep_time
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def restart
|
28
|
+
stop
|
29
|
+
start
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_go_command
|
33
|
+
%{cd #{Dir.pwd} && go run #{@file}}
|
34
|
+
end
|
35
|
+
|
36
|
+
def ps_go_pid
|
37
|
+
`ps aux | awk '/a.out/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i }
|
38
|
+
end
|
39
|
+
|
40
|
+
def sleep_time
|
41
|
+
options[:timeout].to_f / MAX_WAIT_COUNT.to_f
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def run_go_command!
|
46
|
+
@pid = fork do
|
47
|
+
exec build_go_command
|
48
|
+
end
|
49
|
+
@pid
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/guard/go.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
require 'guard/go/runner'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Go < ::Guard::Guard
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
def initialize(watchers = [], options = {})
|
11
|
+
super
|
12
|
+
|
13
|
+
go_file = watchers.first.pattern || 'app.go'
|
14
|
+
|
15
|
+
unless File.exists? go_file
|
16
|
+
raise "Go file #{go_file} not found"
|
17
|
+
end
|
18
|
+
@runner = ::Guard::GoRunner.new(go_file, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def start
|
22
|
+
UI.info "Starting Go..."
|
23
|
+
if pid = @runner.start
|
24
|
+
UI.info "Started Go app, pid #{pid}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_on_change
|
29
|
+
UI.info "Restarting Go..."
|
30
|
+
if @runner.restart
|
31
|
+
UI.info "Go restarted, pid #{@runner.pid}"
|
32
|
+
else
|
33
|
+
UI.info "Go NOT restarted, check your log files."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
@runner.stop
|
39
|
+
UI.info "Stopping Go..."
|
40
|
+
Notifier.notify("Until next time...", :title => "Go shutting down.", :image => :pending)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/guard-go.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'guard/go'
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-go
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Castell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: &70240600442320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70240600442320
|
25
|
+
description: Guard gem for Go
|
26
|
+
email:
|
27
|
+
- victorcoder@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- guard-go.gemspec
|
38
|
+
- lib/guard-go.rb
|
39
|
+
- lib/guard/go.rb
|
40
|
+
- lib/guard/go/runner.rb
|
41
|
+
- lib/guard/go/templates/Guardfile
|
42
|
+
- lib/guard/go/version.rb
|
43
|
+
homepage: ''
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.11
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Guard gem for launching go files
|
67
|
+
test_files: []
|