From 400b85de119dee06628b8eb78dbc2a72365cd25d Mon Sep 17 00:00:00 2001 From: Egor Kovetskiy Date: Wed, 17 Mar 2021 09:24:26 +0300 Subject: [PATCH] option to turn off color output, close #69 --- main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 79b017e..c4a6793 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,8 @@ Options: --minor-edit Don't send notifications while updating Confluence page. --debug Enable debug logs. --trace Enable trace logs. + --color Display logs in color. Possible values: auto, never. + [default: auto] -h --help Show this screen and call 911. -v --version Show version. ` @@ -65,6 +67,7 @@ func main() { editLock = args["-k"].(bool) dropH1 = args["--drop-h1"].(bool) minorEdit = args["--minor-edit"].(bool) + color = args["--color"].(string) ) if args["--debug"].(bool) { @@ -75,6 +78,15 @@ func main() { log.SetLevel(lorg.LevelTrace) } + if color == "never" { + log.GetLogger().SetFormat( + lorg.NewFormat( + `${time:2006-01-02 15:04:05.000} ${level:%s:left:true} ${prefix}%s`, + ), + ) + log.GetLogger().SetOutput(os.Stderr) + } + config, err := LoadConfig(filepath.Join(os.Getenv("HOME"), ".config/mark")) if err != nil { log.Fatal(err) @@ -216,7 +228,9 @@ func main() { markdown = mark.CompileAttachmentLinks(markdown, attaches) if dropH1 { - log.Info("Leading H1 heading will be excluded from the Confluence output") + log.Info( + "Leading H1 heading will be excluded from the Confluence output", + ) markdown = mark.DropDocumentLeadingH1(markdown) }