vcastellm / guard-go

Run and restart go programs when changed
MIT License
24 stars 13 forks source link

Issue getting go application to run with Guard #13

Open Integralist opened 9 years ago

Integralist commented 9 years ago

Hi,

I'm new to using Go and have a working script which doesn't run when using this Guard plugin. By that I mean: the output I get from the Go program, I would expect to see that same output again after the Go program is re-executed by Guard. But I don't I see any output from my Go program at all when running under this Guard plugin.

If I run my Go program like so: go run Concurrency/2.go then I typically see the following output:

I'm listening!
This is boring! 0
This is boring! 1
This is boring! 2
This is boring! 3
This is boring! 4
This is boring! 5
You're boring; I'm leaving.

I would expect to see that same output when the relevant file was re-executed by Guard. But I don't see any such output.

The following is the structure of my Go directory...

.
├── Concurrency
│   ├── 1.go
│   ├── 2.go
├── Gemfile
├── Gemfile.lock
├── Guardfile
└── examples
    ├── constants-example.go
    ├── hello-world.go
    ├── package-example.go
    ├── scope-example.go
    └── types-example.go

Note that I'm not developing a proper Go application; it's just a collection of miscellaneous files. This is simply because I'm playing around with different Go code and so I'm not building a proper application (e.g. nearly all of the files you see all define a main function, where as in a proper Go application there would only be one file that was the entry point to main - AFAIK).

The script I'm trying to have executed when any other files are edited is Concurrency/2.go and the contents of that file looks like the following:

package main
import (
    "fmt"
    "math/rand"
    "time"
)

func main() {
    go boring("This is boring!")

    fmt.Println("I'm listening!")
    time.Sleep(2 * time.Second)
    fmt.Println("You're boring; I'm leaving.")
}

func boring(msg string) {
    for i := 0; ; i++ {
        fmt.Println(msg, i)
        time.Sleep(time.Duration(rand.Intn(1e3)) * time.Millisecond)
    }
}

The Guardfile looks like the following:

guard "go", :server => "Concurrency/2.go" do
  watch(%r{^(.+)\.go$}) { |match| puts match }
end

The command I'm running is: bundle exec guard which outputs...

12:11:00 - INFO - Guard is using Tmux to send notifications.
12:11:00 - INFO - Guard is using TerminalTitle to send notifications.
12:11:00 - INFO - Running /Users/markmcdonnell/Box Sync/Library/Go/Concurrency/2.go...
sh: line 0: cd: /Users/markmcdonnell/Box: No such file or directory
12:11:00 - INFO - Started Go app, pid 4167
12:11:00 - INFO - Guard is now watching at '/Users/markmcdonnell/Box Sync/Library/Go'

Notice there is also a problem with the fact that I keep my files sync'ed using Box and that has a space in its directory name and so somewhere the plugin seems to be trying to cd into the directory but can't as the path isn't being escaped properly.

When I edit another file (e.g. examples/constants-example.go) then I see the following output:

[1] guard(main)> ["examples/constants-example.go", "examples/constants-example"]
12:23:08 - INFO - Running /Users/markmcdonnell/Box Sync/Library/Go/Concurrency/2.go...
sh: line 0: cd: /Users/markmcdonnell/Box: No such file or directory
12:23:08 - INFO - Started Go app, pid 4661

So it has watched the set of files correctly; it still tries to cd into a directory incorrectly though. But more importantly I would have expected to have seen the output of the Go problem?