Beispiel #1
0
func handleExit(client service.Client, t *Term) (error, int) {
	fullHistoryFile, err := getConfigFilePath(historyFile)
	if err != nil {
		fmt.Println("Error saving history file:", err)
	} else {
		if f, err := os.OpenFile(fullHistoryFile, os.O_RDWR, 0666); err == nil {
			_, err := t.line.WriteHistory(f)
			if err != nil {
				fmt.Println("readline history error: ", err)
			}
			f.Close()
		}
	}

	kill := true
	if client.AttachedToExistingProcess() {
		answer, err := t.line.Prompt("Would you like to kill the process? [Y/n] ")
		if err != nil {
			return io.EOF, 2
		}
		answer = strings.ToLower(strings.TrimSpace(answer))
		kill = (answer != "n" && answer != "no")
	}
	err = client.Detach(kill)
	if err != nil {
		return err, 1
	}
	return nil, 0
}