diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-11-25 23:51:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-25 23:51:08 -0500 |
commit | 89fbf38f73c7c380d28045e7e3feb0ad7867769b (patch) | |
tree | 2a0b71e70b0949d1f1a70d371a2b5f29f61df2ba /main.go | |
parent | 2b19466b38c69310a85d407343cd174ec6e1d0c3 (diff) |
fix: logs, readme, release version (#18)
* Implement logsink instead of relying on /dev/null
* Add version during build to `--help`
* Update README roadmap
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -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()) |