Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow passing arguments (:args) to the program

  • Loading branch information...
commit f48b9975bbe657e3a9666b2a881c24e984b8e664 1 parent 6c56f7e
@dmantilla dmantilla authored
View
9 README.md
@@ -4,7 +4,7 @@ Guard Go runs go programs and restart when file changes
## Installation
-# For gophers
+### For gophers
You must have a working Ruby installation, then:
@@ -12,7 +12,7 @@ You must have a working Ruby installation, then:
$ cd /your/project/dir
$ bundle init
-# For gophers and Rubysts
+### For gophers and Rubysts
Add this line to your application's Gemfile:
@@ -38,7 +38,8 @@ Edit this and configure your application file name and desired options.
Options defaults to:
-:server => 'app.go' - Go source file to run
-:test => false - To run go test insted of the app.
+ :server => 'app.go' # Go source file to run
+ :test => false # To run go test insted of the app.
+ :args => [] # Parameters, e.g. :args => 420, :args => [420, 120], :args => ["one", "two"]
$ bundle exec guard
View
17 lib/guard/go.rb
@@ -12,10 +12,13 @@ def initialize(watchers = [], options = {})
defaults = {
:server => 'app.go',
- :test => false
+ :test => false,
+ :args => []
}
@options = defaults.merge(options)
+ @options[:args] = wrap_args(@options[:args])
+ @options[:args_to_s] = @options[:args].join(" ")
@runner = ::Guard::GoRunner.new(@options)
end
@@ -41,7 +44,7 @@ def start_info
if @options[:test]
UI.info "Running go test..."
else
- UI.info "Running #{options[:server]}..."
+ UI.info "Running #{options[:server] } #{options[:args_to_s]} ..."
end
end
@@ -53,5 +56,15 @@ def run_info(pid)
UI.info "Go command failed, check your log files."
end
end
+
+ def wrap_args(obj)
+ if obj.nil?
+ []
+ elif obj.respond_to?(:to_ary)
+ obj.to_ary || [obj]
+ else
+ [obj]
+ end
+ end
end
end
View
2  lib/guard/go/runner.rb
@@ -32,7 +32,7 @@ def build_go_command
if @options[:test]
%{cd #{Dir.pwd} && go test}
else
- %{cd #{Dir.pwd} && go run #{@options[:server]} &}
+ %{cd #{Dir.pwd} && go run #{@options[:server]} #{@options[:args_to_s]} &}
end
end
View
2  lib/guard/go/version.rb
@@ -1,5 +1,5 @@
module Guard
module GoVersion
- VERSION = "0.0.4"
+ VERSION = "0.0.5"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.