From 2f224240bfee04c3f12a9f8cdd820de2fc9179b6 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Wed, 17 Aug 2016 22:35:18 +0300 Subject: [PATCH] suppress error if configuration file not exists --- client.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/client.go b/client.go index 514695e..5dd334d 100644 --- a/client.go +++ b/client.go @@ -29,22 +29,26 @@ func client() { nav := newNav(ui.wins[0].h) app := &App{ui, nav} - rcFile, err := os.Open(gConfigPath) - if err != nil { - msg := fmt.Sprintf("opening configuration file: %s", err) - app.ui.message = msg - log.Printf(msg) - } else { - app.ui.echoFileInfo(app.nav) - } - defer rcFile.Close() + if _, err := os.Stat(gConfigPath); err == nil { + log.Printf("reading configuration file: %s", gConfigPath) - p := newParser(rcFile) - for p.parse() { - p.expr.eval(app, nil) - } + rcFile, err := os.Open(gConfigPath) + if err != nil { + msg := fmt.Sprintf("opening configuration file: %s", err) + app.ui.message = msg + log.Printf(msg) + } else { + app.ui.echoFileInfo(app.nav) + } + defer rcFile.Close() - // TODO: parser error check + p := newParser(rcFile) + for p.parse() { + p.expr.eval(app, nil) + } + + // TODO: parser error check + } app.ui.draw(app.nav)