From 89fbf38f73c7c380d28045e7e3feb0ad7867769b Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Mon, 25 Nov 2024 23:51:08 -0500 Subject: fix: logs, readme, release version (#18) * Implement logsink instead of relying on /dev/null * Add version during build to `--help` * Update README roadmap --- main.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index db483e5..48121a7 100644 --- a/main.go +++ b/main.go @@ -3,23 +3,23 @@ package main import ( "log/slog" "os" + "time" + "github.com/ChausseBenjamin/termpicker/internal/logging" "github.com/ChausseBenjamin/termpicker/internal/switcher" "github.com/ChausseBenjamin/termpicker/internal/util" tea "github.com/charmbracelet/bubbletea" "github.com/urfave/cli/v2" ) -func AppAction(ctx *cli.Context) error { - logFile, err := os.Create(ctx.String(flagLogfile)) - if err != nil { - slog.Error("Failed to create log file", util.ErrKey, err.Error()) - os.Exit(1) - } - defer logFile.Close() +var ( // Set by the build system + version = "DEVELOPMENT-SNAPSHOT" + date = "" +) - handler := slog.NewJSONHandler(logFile, nil) - slog.SetDefault(slog.New(handler)) +func AppAction(ctx *cli.Context) error { + logfile := logging.Setup(ctx.String("logfile")) + defer logfile.Close() slog.Info("Starting Termpicker") @@ -37,11 +37,17 @@ func AppAction(ctx *cli.Context) error { } func main() { + compileDate, _ := time.Parse(time.RFC3339, date) app := &cli.App{ Name: "Termpicker", Usage: "A terminal-based color picker", Action: AppAction, - Flags: AppFlags, + Authors: []*cli.Author{ + {Name: "Benjamin Chausse", Email: "benjamin@chausse.xyz"}, + }, + Version: version, + Flags: AppFlags, + Compiled: compileDate, } if err := app.Run(os.Args); err != nil { slog.Error("Program crashed", util.ErrKey, err.Error()) -- cgit v1.2.3