From aa323b86f979936cb1c8eda3301e13683f4c5a0f Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Fri, 27 Dec 2024 02:00:21 -0500 Subject: migrate to urfave/cli V3 --- main.go | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 5511ac6..f8dacf8 100644 --- a/main.go +++ b/main.go @@ -1,31 +1,29 @@ package main import ( + "context" "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" + "github.com/urfave/cli/v3" ) -var ( // Set by the build system - version = "compiled" - date = "" -) +// Set by the build system +var version = "compiled" -func AppAction(ctx *cli.Context) error { - logfile := logging.Setup(ctx.String("logfile")) +func AppAction(ctx context.Context, cmd *cli.Command) error { + logfile := logging.Setup(cmd.String("logfile")) defer logfile.Close() slog.Info("Starting Termpicker") sw := switcher.New() - if colorStr := ctx.String("color"); colorStr != "" { + if colorStr := cmd.String("color"); colorStr != "" { sw.NewNotice(sw.SetColorFromText(colorStr)) } @@ -37,19 +35,16 @@ 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, - Authors: []*cli.Author{ - {Name: "Benjamin Chausse", Email: "benjamin@chausse.xyz"}, - }, - Version: version, - Flags: AppFlags, - Compiled: compileDate, + app := &cli.Command{ + Name: "Termpicker", + Usage: "A terminal-based color picker", + Action: AppAction, + Authors: []any{"Benjamin Chausse "}, + Version: version, + Flags: AppFlags, + EnableShellCompletion: true, } - if err := app.Run(os.Args); err != nil { + if err := app.Run(context.Background(), os.Args); err != nil { slog.Error("Program crashed", util.ErrKey, err.Error()) os.Exit(1) } -- cgit v1.2.3