本文整理匯總了Golang中github.com/9seconds/ah/app/environments.Environment.GetTraceFileName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Environment.GetTraceFileName方法的具體用法?Golang Environment.GetTraceFileName怎麽用?Golang Environment.GetTraceFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/9seconds/ah/app/environments.Environment
的用法示例。
在下文中一共展示了Environment.GetTraceFileName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListTrace
// ListTrace implements l command (list trace).
func ListTrace(argument string, env *environments.Environment) {
number, err := strconv.Atoi(argument)
if err != nil || number < 0 {
utils.Logger.Panicf("Cannot convert argument to a command number: %s", argument)
}
commands, err := historyentries.GetCommands(historyentries.GetCommandsPrecise, nil, env, number)
if err != nil {
utils.Logger.Panic(err)
}
command := commands.Result().(historyentries.HistoryEntry)
hashFilename := command.GetTraceName()
filename := env.GetTraceFileName(hashFilename)
if _, err := os.Stat(filename); os.IsNotExist(err) {
utils.Logger.Panicf("Output for %s is not exist", argument)
}
file := utils.Open(filename)
defer file.Close()
ungzippedFile, err := gzip.NewReader(file)
if err != nil {
utils.Logger.Panic(err)
}
defer ungzippedFile.Close()
scanner := bufio.NewScanner(ungzippedFile)
for scanner.Scan() {
os.Stdout.WriteString(scanner.Text())
os.Stdout.WriteString("\n")
}
if err := scanner.Err(); err != nil {
utils.Logger.Panic(err)
}
}
示例2: Tee
// Tee implements t (trace, tee) command.
func Tee(input string, interactive bool, pseudoTTY bool, env *environments.Environment) {
output, err := ioutil.TempFile(env.TmpDir, "ah")
if err != nil {
utils.Logger.Panic("Cannot create temporary file")
}
bufferedOutput := bufio.NewWriter(output)
gzippedWrapper := utils.NewSynchronizedWriter(gzip.NewWriter(bufferedOutput))
combinedStdout := io.MultiWriter(os.Stdout, gzippedWrapper)
combinedStderr := io.MultiWriter(os.Stderr, gzippedWrapper)
var commandError *exec.ExitError
defer func() {
// defer here because command may cause a panic but we do not want to lose any output
gzippedWrapper.Close()
bufferedOutput.Flush()
output.Close()
if hash, err := getPreciseHash(input, env); err == nil {
err = os.Rename(output.Name(), env.GetTraceFileName(hash))
if err != nil {
utils.Logger.Errorf("Cannot save trace: %v. Get it here: %s", err, output.Name())
} else {
os.Remove(output.Name())
}
} else {
utils.Logger.Errorf("Error occured on fetching command number: %v", err)
}
if commandError != nil {
os.Exit(utils.GetStatusCode(commandError))
}
}()
commandError = utils.Exec(input,
string(env.Shell), interactive, pseudoTTY,
os.Stdin, combinedStdout, combinedStderr)
}