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:
// Stop running command
cmd.Process.Kill()
return "killed", nil
return msgStop, nil
case err := <-done:
// Command completed
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 {
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 {
build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+".exe", args...)
} 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))+extWindows, args...)
} else {
path := filepath.Join(p.base, filepath.Base(p.path))
if _, err = os.Stat(path); err == nil {
build = exec.Command(path, args...)
} else if _, err = os.Stat(path + ".exe"); err == nil {
build = exec.Command(path+".exe", args...)
} else if _, err = os.Stat(path + extWindows); err == nil {
build = exec.Command(path+extWindows, args...)
} else {
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", ":")

View File

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

View File

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