Exemplo n.º 1
0
Arquivo: file.go Projeto: 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
}
Exemplo n.º 2
0
Arquivo: util.go Projeto: 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
}