Esempio n. 1
0
File: file.go Progetto: arschles/gci
// ReadOrDie calls Read and if it returned an error, logs and exits
func ReadOrDie(name string) *File {
	cf, err := Read(name)
	if err != nil {
		log.Die("Reading config file %s [%s]", name, err)
		return nil
	}
	return cf
}
Esempio n. 2
0
File: util.go Progetto: arschles/gci
// execOrDie prints the command before executing it, executes it and returns its output.
// if the command failed, calls log.Die with a helpful error message
func runOrDie(cmd *exec.Cmd, env []string) []byte {
	cmd.Env = env

	log.Info(cmdStr(cmd))
	log.Debug("Env: %s", envStr(cmd))

	out, err := cmd.CombinedOutput()
	if err != nil {
		var s string
		if len(out) > 0 {
			s += fmt.Sprintf("%s\n", string(out))
		}
		if err != nil {
			s += err.Error()
		}
		log.Die(s)
	}
	return out
}