Пример #1
0
func (s *Shell) Run() (result *task.Result, err error) {
	result, err = task.DoRun(func(result *task.Result) (err error) {
		result.Module = "shell"
		result.Extra["cmd"] = s.Command
		if s.Chdir != "" {
			result.Extra["chdir"] = s.Chdir
		}
		if s.Creates != "" {
			result.Extra["creates"] = s.Creates
		}

		var shell string
		if s.Shell == "" {
			shell = DEFAULT_SHELL
		} else {
			shell = s.Shell
		}
		result.Extra["shell"] = shell

		if s.Creates != "" && osutil.Exists(s.Creates) {
			result.Skipped = true
			return
		}

		var command string
		if s.Chdir != "" {
			command = "cd " + executil.QuoteWord(s.Chdir) + "; " + s.Command
		} else {
			command = s.Command
		}
		err = result.ExecCommand(shell, "-c", command)
		return
	})
	return
}
Пример #2
0
func TestExists(t *testing.T) {
	f, err := ioutil.TempFile("", "output-")
	if err != nil {
		t.Fatal(err)
	}

	if !osutil.Exists(f.Name()) {
		t.Fatal("Must exists")
	}

	err = os.Remove(f.Name())
	if err != nil {
		t.Fatal(err)
	}

	if osutil.Exists(f.Name()) {
		t.Fatal("Must not exist")
	}
}