func writeLinerHistory(line *liner.State) { if f, err := os.Create(historyFilename); err != nil { log.Print("Error writing history file: ", err) } else { line.WriteHistory(f) f.Close() } }
// from google/cayley func persist(term *liner.State, path string) error { f, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666) if err != nil { return fmt.Errorf("could not open %q to append history: %v", path, err) } defer f.Close() _, err = term.WriteHistory(f) if err != nil { return fmt.Errorf("could not write history to %q: %v", path, err) } return term.Close() }
func (r *REPL) saveHistory(prompt *liner.State) { if f, err := os.Create(r.historyPath); err == nil { prompt.WriteHistory(f) f.Close() } }