Skip to content

Commit

Permalink
Merge pull request #10 from Aigeruth/feature/go_cmd
Browse files Browse the repository at this point in the history
Add "changable 'go' binary name" feature
  • Loading branch information
Victor Castell committed Aug 25, 2014
2 parents a490acf + 9e908e5 commit 471175e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -9,7 +9,7 @@ Guard Go runs go programs and restart when file changes
You must have a working Ruby installation, then:

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

### For gophers and Rubysts
Expand All @@ -32,7 +32,7 @@ Read Guard usage https://github.com/guard/guard#usage

$ bundle exec guard init go

This will create your Guardfile.
This will create your Guardfile.

Edit this and configure your application file name and desired options.

Expand All @@ -42,5 +42,6 @@ Options defaults to:
:test => false # To run go test instead of the app.
:build_only => false # To build instead of run.
:args => [] # Parameters, e.g. :args => 420, :args => [420, 120], :args => ["one", "two"]
:cmd => 'go' # Name of the Go commandline tool

$ bundle exec guard
15 changes: 8 additions & 7 deletions lib/guard/go.rb
Expand Up @@ -4,18 +4,19 @@
require 'guard/go/runner'

module Guard
class Go < ::Guard::Guard
class Go < ::Guard::Guard
attr_reader :options

def initialize(watchers = [], options = {})
super

defaults = {
:server => 'app.go',
:test => false,
:args => []
server: 'app.go',
test: false,
args: [],
cmd: 'go'
}

@options = defaults.merge(options)
@options[:args] = wrap_args(@options[:args])
@options[:args_to_s] = @options[:args].join(" ")
Expand Down Expand Up @@ -51,7 +52,7 @@ def start_info
def run_info(pid)
return if @options[:test]
if pid
UI.info "Started Go app, pid #{pid}"
UI.info "Started Go app, pid #{pid}"
else
UI.info "Go command failed, check your log files."
end
Expand Down
6 changes: 3 additions & 3 deletions lib/guard/go/runner.rb
Expand Up @@ -43,12 +43,12 @@ def sleep_time
private
def run_go_command!
if @options[:test]
@proc = ChildProcess.build("go", "test")
@proc = ChildProcess.build(@options[:cmd], "test")
else
if @options[:build_only]
@proc = ChildProcess.build("go", "build")
@proc = ChildProcess.build(@options[:cmd], "build")
else
@proc = ChildProcess.build("go", "run", @options[:server], @options[:args_to_s])
@proc = ChildProcess.build(@options[:cmd], "run", @options[:server], @options[:args_to_s])
end
end

Expand Down

0 comments on commit 471175e

Please sign in to comment.