예제 #1
0
파일: main.go 프로젝트: lht/termite
func TryRunLocally(command string, topdir string) (exit *os.Waitmsg, rule termite.LocalRule) {
	decider := termite.NewLocalDecider(topdir)
	if !(len(os.Args) == 3 && os.Args[0] == _SHELL && os.Args[1] == "-c") {
		return
	}

	rule = decider.ShouldRunLocally(command)
	if rule.Local {
		env := os.Environ()
		if !rule.Recurse {
			env = cleanEnv(env)
		}

		proc, err := os.StartProcess(_SHELL, os.Args, &os.ProcAttr{
			Env:   env,
			Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
		})
		if err != nil {
			log.Fatalf("os.StartProcess() for %s: %v", command, err)
		}
		msg, err := proc.Wait(0)
		if err != nil {
			log.Fatalf("proc.Wait() for %s: %v", command, err)
		}
		return msg, rule
	}

	return
}
예제 #2
0
파일: main.go 프로젝트: hanwen/termite
func PrepareRun(cmd string, dir string, topdir string) (*termite.WorkRequest, *termite.LocalRule) {
	cmd = termite.MakeUnescape(cmd)
	if cmd == ":" || strings.TrimRight(cmd, " ") == "" {
		os.Exit(0)
	}

	req := NewWorkRequest(cmd, dir, topdir)
	TryRunDirect(req)

	decider := termite.NewLocalDecider(topdir)
	rule := decider.ShouldRunLocally(cmd)
	if rule != nil {
		req.Debug = rule.Debug
		return req, rule
	}

	return req, nil
}