From 456c99d7dbd61295c4991365d17909036a153818 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 11 Jun 2023 15:48:27 +0100 Subject: [PATCH] args: fix help not usually showing another weird side effect of the line cache/logging stuff. The true stderr is now stored in the "stderr" global variable and is used to print the help screen. --- args.go | 13 +++++++++---- log.go | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/args.go b/args.go index c06085f..398c2a4 100644 --- a/args.go +++ b/args.go @@ -75,18 +75,23 @@ func (app *appContext) loadArgs(firstCall bool) { os.Setenv("JFA_DATAPATH", app.dataPath) } -/* Adds start/stop/systemd to help message, and +/* + Adds start/stop/systemd to help message, and + also gets rid of usage for shorthand flags, and merge them with the full-length one. implementation is 🤢, will clean this up eventually. + -h SHORTHAND -help prints this message. + becomes: + -help, -h prints this message. */ func helpFunc() { - fmt.Fprint(os.Stderr, `Usage of jfa-go: + fmt.Fprint(stderr, `Usage of jfa-go: start start jfa-go as a daemon and run in the background. stop @@ -99,7 +104,7 @@ func helpFunc() { // Write defaults into buffer then remove any shorthands flag.CommandLine.SetOutput(&b) flag.PrintDefaults() - flag.CommandLine.SetOutput(os.Stderr) + flag.CommandLine.SetOutput(stderr) scanner := bufio.NewScanner(&b) out := "" line := scanner.Text() @@ -150,5 +155,5 @@ func helpFunc() { lastLine = true } } - fmt.Fprint(os.Stderr, out) + fmt.Fprint(stderr, out) } diff --git a/log.go b/log.go index 2d80a38..636f342 100644 --- a/log.go +++ b/log.go @@ -14,6 +14,8 @@ import ( var logPath string = filepath.Join(temp, "jfa-go.log") var lineCache = linecache.NewLineCache(100) +var stderr = os.Stderr + func logOutput() (closeFunc func(), err error) { old := os.Stdout writers := []io.Writer{old, colorStripper{lineCache}}