Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for arguments to the Go program #1

Merged
merged 2 commits into from
Sep 9, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Guard Go runs go programs and restart when file changes

## Installation

# For gophers
### For gophers

You must have a working Ruby installation, then:

$ gem install bundler
$ cd /your/project/dir
$ bundle init

# For gophers and Rubysts
### For gophers and Rubysts

Add this line to your application's Gemfile:

Expand All @@ -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
17 changes: 15 additions & 2 deletions lib/guard/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/guard/go/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/guard/go/templates/Guardfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/guard/go/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
module GoVersion
VERSION = "0.0.4"
VERSION = "0.0.5"
end
end