Skip to content

Commit 30a199b

Browse files
author
Victor Castell
committed
Merge pull request #1 from dmantilla/master
Added support for arguments to the Go program
2 parents 6c56f7e + e9be187 commit 30a199b

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Guard Go runs go programs and restart when file changes
44

55
## Installation
66

7-
# For gophers
7+
### For gophers
88

99
You must have a working Ruby installation, then:
1010

1111
$ gem install bundler
1212
$ cd /your/project/dir
1313
$ bundle init
1414

15-
# For gophers and Rubysts
15+
### For gophers and Rubysts
1616

1717
Add this line to your application's Gemfile:
1818

@@ -38,7 +38,8 @@ Edit this and configure your application file name and desired options.
3838

3939
Options defaults to:
4040

41-
:server => 'app.go' - Go source file to run
42-
:test => false - To run go test insted of the app.
41+
:server => 'app.go' # Go source file to run
42+
:test => false # To run go test insted of the app.
43+
:args => [] # Parameters, e.g. :args => 420, :args => [420, 120], :args => ["one", "two"]
4344

4445
$ bundle exec guard

lib/guard/go.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ def initialize(watchers = [], options = {})
1212

1313
defaults = {
1414
:server => 'app.go',
15-
:test => false
15+
:test => false,
16+
:args => []
1617
}
1718

1819
@options = defaults.merge(options)
20+
@options[:args] = wrap_args(@options[:args])
21+
@options[:args_to_s] = @options[:args].join(" ")
1922

2023
@runner = ::Guard::GoRunner.new(@options)
2124
end
@@ -41,7 +44,7 @@ def start_info
4144
if @options[:test]
4245
UI.info "Running go test..."
4346
else
44-
UI.info "Running #{options[:server]}..."
47+
UI.info "Running #{options[:server] } #{options[:args_to_s]} ..."
4548
end
4649
end
4750

@@ -53,5 +56,15 @@ def run_info(pid)
5356
UI.info "Go command failed, check your log files."
5457
end
5558
end
59+
60+
def wrap_args(obj)
61+
if obj.nil?
62+
[]
63+
elif obj.respond_to?(:to_ary)
64+
obj.to_ary || [obj]
65+
else
66+
[obj]
67+
end
68+
end
5669
end
5770
end

lib/guard/go/runner.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def build_go_command
3232
if @options[:test]
3333
%{cd #{Dir.pwd} && go test}
3434
else
35-
%{cd #{Dir.pwd} && go run #{@options[:server]} &}
35+
%{cd #{Dir.pwd} && go run #{@options[:server]} #{@options[:args_to_s]} &}
3636
end
3737
end
3838

lib/guard/go/templates/Guardfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add files and commands to this file, like the example:
22
# watch(%r{file/path}) { `command(s)` }
33
#
4-
guard 'go', :server => 'app.go' do
4+
guard 'go', :server => 'app.go', :args => [] do
55
watch(%r{\.go$})
66
end

lib/guard/go/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Guard
22
module GoVersion
3-
VERSION = "0.0.4"
3+
VERSION = "0.0.5"
44
end
55
end

0 commit comments

Comments
 (0)