From f48b9975bbe657e3a9666b2a881c24e984b8e664 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 7 Sep 2012 22:29:17 -0400 Subject: [PATCH 1/2] Allow passing arguments (:args) to the program --- README.md | 9 +++++---- lib/guard/go.rb | 17 +++++++++++++++-- lib/guard/go/runner.rb | 2 +- lib/guard/go/version.rb | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3cca657..9863b8d 100644 --- a/README.md +++ b/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 diff --git a/lib/guard/go.rb b/lib/guard/go.rb index a5fe767..7b9aa99 100644 --- a/lib/guard/go.rb +++ b/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 diff --git a/lib/guard/go/runner.rb b/lib/guard/go/runner.rb index 7598571..59e2619 100644 --- a/lib/guard/go/runner.rb +++ b/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 diff --git a/lib/guard/go/version.rb b/lib/guard/go/version.rb index 334a5d1..ca32511 100644 --- a/lib/guard/go/version.rb +++ b/lib/guard/go/version.rb @@ -1,5 +1,5 @@ module Guard module GoVersion - VERSION = "0.0.4" + VERSION = "0.0.5" end end From e9be187f3e640f50c89fe2a70394971c81cd93ea Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 7 Sep 2012 22:38:05 -0400 Subject: [PATCH 2/2] adjusted the Guardfile template to include :args as an option --- lib/guard/go/templates/Guardfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guard/go/templates/Guardfile b/lib/guard/go/templates/Guardfile index 0b2bb27..d8d4902 100644 --- a/lib/guard/go/templates/Guardfile +++ b/lib/guard/go/templates/Guardfile @@ -1,6 +1,6 @@ # Add files and commands to this file, like the example: # watch(%r{file/path}) { `command(s)` } # -guard 'go', :server => 'app.go' do +guard 'go', :server => 'app.go', :args => [] do watch(%r{\.go$}) end