コード例 #1
0
ファイル: file.go プロジェクト: 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
}
コード例 #2
0
ファイル: util.go プロジェクト: 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
}