// Main is the entry point of elvish. func Main() { defer rescue() flag.Usage = usage flag.Parse() args := flag.Args() if len(args) > 1 { usage() os.Exit(2) } if *help { usage() os.Exit(0) } if *log != "" { err := util.SetOutputFile(*log) if err != nil { fmt.Println(err) } } if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { Logger.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } handleHupAndQuit() logSignals() ev, st := newEvalerAndStore() defer func() { err := st.Close() if err != nil { fmt.Println("failed to close database:", err) } }() if len(args) == 1 { if *cmd { evalText(ev, "code from -c", args[0]) } else { script(ev, args[0]) } } else if !sys.IsATTY(0) { script(ev, "/dev/stdin") } else { interact(ev, st) } }
func _log(ec *EvalCtx, fname string) { maybeThrow(util.SetOutputFile(fname)) }