strings as const

This commit is contained in:
asoseil 2017-10-16 18:59:35 +02:00
parent 578ac8b069
commit 76bcb5e058
3 changed files with 12 additions and 7 deletions

10
exec.go
View File

@ -39,7 +39,7 @@ func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (s
case <-stop: case <-stop:
// Stop running command // Stop running command
cmd.Process.Kill() cmd.Process.Kill()
return "killed", nil return msgStop, nil
case err := <-done: case err := <-done:
// Command completed // Command completed
if err != nil { if err != nil {
@ -77,14 +77,14 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) {
if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))); err == nil { if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))); err == nil {
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)), args...) build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)), args...)
} else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)) + ".exe"); err == nil { } else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)) + extWindows); err == nil {
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+".exe", args...) build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+extWindows, args...)
} else { } else {
path := filepath.Join(p.base, filepath.Base(p.path)) path := filepath.Join(p.base, filepath.Base(p.path))
if _, err = os.Stat(path); err == nil { if _, err = os.Stat(path); err == nil {
build = exec.Command(path, args...) build = exec.Command(path, args...)
} else if _, err = os.Stat(path + ".exe"); err == nil { } else if _, err = os.Stat(path + extWindows); err == nil {
build = exec.Command(path+".exe", args...) build = exec.Command(path+extWindows, args...)
} else { } else {
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"}) p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"})
p.fatal(nil, "Can't run a not compiled project", ":") p.fatal(nil, "Can't run a not compiled project", ":")

View File

@ -20,7 +20,7 @@ func TestProject_GoCompile(t *testing.T) {
close(stop) close(stop)
select { select {
case v := <-response: case v := <-response:
if v != "killed" { if v != msgStop {
t.Error("Unexpected result", response) t.Error("Unexpected result", response)
} }
case <-time.After(2 * time.Second): case <-time.After(2 * time.Second):

View File

@ -21,6 +21,11 @@ var (
wg sync.WaitGroup wg sync.WaitGroup
) )
const (
msgStop = "killed"
extWindows = extWindows
)
// Watch struct defines options for livereload // Watch struct defines options for livereload
type Watch struct { type Watch struct {
Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"` Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"`
@ -215,7 +220,7 @@ func (p *Project) compile(stop <-chan bool, cmd Cmd) error {
go func() { go func() {
log.Println(p.pname(p.Name, 1), ":", cmd.startTxt) log.Println(p.pname(p.Name, 1), ":", cmd.startTxt)
stream, err := p.goCompile(stop, cmd.method, cmd.Args) stream, err := p.goCompile(stop, cmd.method, cmd.Args)
if stream != "killed" { if stream != msgStop {
channel <- Result{stream, err} channel <- Result{stream, err}
} }
}() }()