240
241 // Start the watching process - it'll check for changes every 100ms.
242 if err := watch.Start(time.Millisecond * 100); err != nil {
243 log.Fatalln(err)244 }
245}
235 // Watch config file for changes.
236 absPath, _ := utils.ExpandHomeDir(wtfApp.configFilePath)
237 if err := watch.Add(absPath); err != nil {
238 log.Fatalln(err)239 }
240
241 // Start the watching process - it'll check for changes every 100ms.
225 // Usually happens because the watcher looks for the file as the OS is updating it
226 continue
227 }
228 log.Fatalln(err)229 case <-watch.Closed:
230 return
231 }
112 wtfApp.Stop()
113 wtfApp.TViewApp.Stop()
114 wtfApp.DisplayExitMessage()
115 os.Exit(0)116}
117
118// Execute starts the underlying tview app
58 wtfApp.widgets = MakeWidgets(wtfApp.TViewApp, wtfApp.pages, wtfApp.config, wtfApp.redrawChan)
59 if len(wtfApp.widgets) == 0 {
60 fmt.Println("No modules were defined. Make sure you have at least one properly defined widget")
61 os.Exit(1) 62 }
63
64 wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
Packages exposing functions that can stop program execution by exiting are hard to reuse. Program exits in functions other than main() or init() are not encouraged.
func nonMainFunc() {
safelyExit := true // somehow arrive at this value
if safelyExit {
os.Exit(0)
}
}
func main() {
nonMainFunc()
}
func nonMainFunc() bool {
safelyExit := true // somehow arrive at this value
}
func main() {
safelyExit := nonMainFunc()
if safelyExit {
os.Exit(0)
}
}