From 1246d13c16840ca055720a28b0bc0adb9bd74312 Mon Sep 17 00:00:00 2001 From: Jesse Millar Date: Fri, 24 Jul 2020 12:46:18 -0500 Subject: [PATCH] Read default styles before reading from the file system (#73) --- glamour.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/glamour.go b/glamour.go index 90e49ec..3e69e7e 100644 --- a/glamour.go +++ b/glamour.go @@ -135,20 +135,17 @@ func WithEnvironmentConfig() TermRendererOption { // standard style. func WithStylePath(stylePath string) TermRendererOption { return func(tr *TermRenderer) error { - jsonBytes, err := ioutil.ReadFile(stylePath) - switch { - case err == nil: - return json.Unmarshal(jsonBytes, &tr.ansiOptions.Styles) - case os.IsNotExist(err): - styles, err := getDefaultStyle(stylePath) + styles, err := getDefaultStyle(stylePath) + if err != nil { + jsonBytes, err := ioutil.ReadFile(stylePath) if err != nil { return err } - tr.ansiOptions.Styles = *styles - return nil - default: - return err + + return json.Unmarshal(jsonBytes, &tr.ansiOptions.Styles) } + tr.ansiOptions.Styles = *styles + return nil } }